How do you clone a path resource in Silverlight? - silverlight

I have a resource defined in my Xaml file as follows:
<Path x:Key="myPath"
Data="M14.773241,18.080208 C12.373256,18.080208 10.239936,19.30687 10.239936,27.573483
L10.239936,36.106766 C10.239936,45.440037 12.586588,46.506699 14.986573,46.506699
C18.613216,46.506699 19.359879,42.400059 19.359879,35.3601 L19.359879,27.733482
C19.359879,20.05353 17.386559,18.080208 14.773241,18.080208 z M14.879907,11.786915
C17.973221,11.786915 22.293194,13.013573 24.906511,17.920212 C26.773167,21.386856
27.519829,27.093487 27.519829,32.213455 C27.519829,34.506775 27.306496,41.706726
24.906511,46.453365 C23.626518,49.013351 20.906536,52.799992 15.199905,52.799992
C2.1333201,52.799992 2.1333201,37.600086 2.1333201,32.160122 C2.1333201,28.05348
2.1333201,22.666847 4.4266391,18.453541 C5.8666301,15.840225 8.639946,11.786915
14.879907,11.786915 z"
/>
I want to able to add multiple "instances" of this path (and several others) to a StackPanel. Of course, I can't simply add "myPath" to the panel since it's already a child of another container.
However, I can't seem to be able to clone the path either. I've tried:
Path clone = new Path()
{
Data = source.Data
};
But no luck...exception about value being out of expected range.
Finally, I tried digging into source.Data (a PathGeometry), but it contains no PathFigures...I have no idea why, since the Path does render if I copy it from the resource section to a panel directly.
What gives?
Thanks,
Sergio

Put the path data in a string resource:
<Page.Resources>
<system:String x:Key="PathData">
M14.773241,18.080208 C12.373256,18.080208 10.239936,19.30687 10.239936,27.573483
L10.239936,36.106766 C10.239936,45.440037 12.586588,46.506699 14.986573,46.506699
C18.613216,46.506699 19.359879,42.400059 19.359879,35.3601 L19.359879,27.733482
C19.359879,20.05353 17.386559,18.080208 14.773241,18.080208 z M14.879907,11.786915
C17.973221,11.786915 22.293194,13.013573 24.906511,17.920212 C26.773167,21.386856
27.519829,27.093487 27.519829,32.213455 C27.519829,34.506775 27.306496,41.706726
24.906511,46.453365 C23.626518,49.013351 20.906536,52.799992 15.199905,52.799992
C2.1333201,52.799992 2.1333201,37.600086 2.1333201,32.160122 C2.1333201,28.05348
2.1333201,22.666847 4.4266391,18.453541 C5.8666301,15.840225 8.639946,11.786915
14.879907,11.786915 z
</system:String>
</Page.Resources>
And to use it:
<Path x:Name="Path1" Data="{StaticResource PathData}" Fill="Blue" ... />
<Path x:Name="Path2" Data="{StaticResource PathData}" Fill="Red" ... />
You'll need this in your XAML declaration:
xmlns:system="clr-namespace:System;assembly=mscorlib"
If you want to create paths programmatically using a common path string, Silverlight is missing a bit of key functionality that WPF has -- so you have to kludge it:
string pathXaml =
#"<Path xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
Data=""path_data_goes_here"" />";
Path path = (Path)System.Windows.Markup.XamlReader.Load(pathXaml);

Related

While importing product XML in demandware how to append images in same product?

I have two product XML look like:
1:- product-1.xml
.
.
.
.
<images merge-mode="add">
<image-group view-type="large">
<image path="product-123.jpg" />
</image-group>
</images>
.
.
2:- product-1-1.xml
.
.
.
.
<images merge-mode="add">
<image-group view-type="large">
<image path="product-124.jpg" />
<image path="product-125.jpg" />
</image-group>
</images>
.
.
I am importing both the files and I want to append the images for the same product (PRODUCT123) as
<images merge-mode="add">
<image-group view-type="large">
<image path="product-123.jpg" />
<image path="product-124.jpg" />
<image path="product-125.jpg" />
</image-group>
</images>
but it's not appending the images.
I used merge-mode="merge" also for the same but not getting the result as I expected.
Could anyone help me out that where I am doing wrong?
Sadly, what you want to achieve is currently not supported by the Salesforce B2C Commerce platform.
You cannot split the images of an image group into several files and expect that they will be merged.
Indeed, the file import mode should be MERGE, but what you have tried as element merge-mode="add" is not supported, and you should have received a warning when you have imported the file.
If you look at catalog.xsd schema from the documentation you would see the following under complexType.Product.Images type definition:
<xsd:attribute name="merge-mode" type="simpleType.MergeMode" default="merge" use="optional">
<xsd:annotation>
<xsd:documentation>
Used to control if specified image groups will be merged to or replace the existing image specification.
The values "merge" and "replace" are the only ones supported for the "merge-mode" attribute.
Attribute should only be used in import MERGE and UPDATE modes. In import REPLACE mode, using the "merge-mode" attribute is not
sensible, because existing image groups will always be removed before importing the image groups
specified in the import file.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
P.S. I would suggest that you look for an alternative solution for merging the data about images before sending it to Salesforce B2C Commerce instance.
Are you using ImportCatalog pipelet? Please check job configuration, import mode should be MERGE.

MediaElement can't play network paths containing a #

My F:\ drive is a mapped network drive.
I have two videos on it:
F:\Video1.mp4
F:\Video#1.mp4
I'd like to use a MediaElement to play them.
<MediaElement Source="F:\Video1.mp4" /> <!-- works -->
<MediaElement Source="F:\Video#1.mp4" /> <!-- doesn't work -->
It seems the # is being treated as %23 when it is a network path. This works fine if F:\ is a local drive.
How can I make F:\Video#1.mp4 work? It is a legitimate path.
Try creating a URI with file:/// prepended:
mediaElement.Source = new Uri( "file:///" + #"F:\Video#1.mp4" );
This Social post says that worked for them.

Preview actual image of PathGeometry in WPF MVVM

In my application there is a common Icon.xaml file which contains many PathGeometry Figures having unique key names like as shown below.
<PathGeometry x:Key="CloseGeometry" Figures="m 357.0883 499.0572 12.62375 12.6275 5.31375 -5.31625 -12.62625 -12.62625 12.62625 -12.61875 -5.31375 -5.3125 -12.62375 12.62 -12.6325 -12.62 -5.30375 5.3125 12.6175 12.61875 -12.6175 12.62625 5.30375 5.31625 12.6325 -12.6275 z"/>
<PathGeometry x:Key="NormalGeometry" Figures="M4.3685131,23.127279L4.3685131,47.283243 47.117023,47.283243 47.117023,23.127279z M25.087107,13.948568C23.539013,13.948568 22.286318,15.201555 22.286318,16.74834 22.286318,18.292325 23.539013,19.547214 25.087107,19.547214 26.6327,19.547214 27.886597,18.292325 27.886597,16.74834 27.886597,15.201555 26.6327,13.948568 25.087107,13.948568z M16.126242,13.948568C14.580646,13.948568 13.326751,15.201555 13.326751,16.74834 13.326751,18.292325 14.580646,19.547214 16.126242,19.547214 17.673136,19.547214 18.928329,18.292325 18.928329,16.74834 18.928329,15.201555 17.673136,13.948568 16.126242,13.948568z M7.1679735,13.948568C5.621069,13.948568 4.3685136,15.201555 4.3685131,16.74834 4.3685136,18.292325 5.621069,19.547214 7.1679735,19.547214 8.713438,19.547214 9.9674625,18.292325 9.9674625,16.74834 9.9674625,15.201555 8.713438,13.948568 7.1679735,13.948568z M0,10.684L53.755001,10.684 53.755001,51.668001 0,51.668001z M8.5679998,0L58.668022,0 64,0 64,5.6864691 64,45.317999 58.668022,45.317999 58.668022,5.6864691 8.5679998,5.6864691z"/>
<PathGeometry x:Key="MaximiseGeometry" Figures="M5.2010002,14.812L5.2010002,43.573997 56.098,43.573997 56.098,14.812z M29.868601,3.8869994C28.026201,3.8869996 26.534,5.3791947 26.534,7.2190399 26.534,9.0588851 28.026201,10.553 29.868601,10.553 31.7085,10.553 33.202,9.0588851 33.202,7.2190399 33.202,5.3791947 31.7085,3.8869996 29.868601,3.8869994z M19.200649,3.8869994C17.359457,3.8869996 15.867001,5.3791947 15.867001,7.2190399 15.867001,9.0588851 17.359457,10.553 19.200649,10.553 21.042044,10.553 22.536999,9.0588851 22.536999,7.2190399 22.536999,5.3791947 21.042044,3.8869996 19.200649,3.8869994z M8.5339746,3.8869994C6.6931,3.8869996 5.2010002,5.3791947 5.2010002,7.2190399 5.2010002,9.0588851 6.6931,10.553 8.5339746,10.553 10.37495,10.553 11.867,9.0588851 11.867,7.2190399 11.867,5.3791947 10.37495,3.8869996 8.5339746,3.8869994z M0,0L63.999001,0 63.999001,48.792999 0,48.792999z"/>
<PathGeometry x:Key="MinimiseGeometry" Figures="M 0 1, 1 1 "/>
.....
But my problem is that there are around 300 to 400 different PathGeometries and it becomes difficult to check whether particular type of Image exists or not.
Example:
If new WPF form is gettign developed by programmer in which s\he needs to use delete Icon then s\he will first check in Icon.xaml file whether it already exists or not, if not then it will be added.But this checking needs to be done manually which is a pain.
So is there any simplest way to preview or check whether particular iamge exists or not.
Currently, I konw two tools can help you preview PathGeometry data of xaml.
XamlPadX
Download: XamlPadX v4.0.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Path Stroke="Black" StrokeThickness="2" Data="M4.3685131,23.127279L4.3685131,47.283243 47.117023,47.283243 47.117023,23.127279z M25.087107,13.948568C23.539013,13.948568 22.286318,15.201555 22.286318,16.74834 22.286318,18.292325 23.539013,19.547214 25.087107,19.547214 26.6327,19.547214 27.886597,18.292325 27.886597,16.74834 27.886597,15.201555 26.6327,13.948568 25.087107,13.948568z M16.126242,13.948568C14.580646,13.948568 13.326751,15.201555 13.326751,16.74834 13.326751,18.292325 14.580646,19.547214 16.126242,19.547214 17.673136,19.547214 18.928329,18.292325 18.928329,16.74834 18.928329,15.201555 17.673136,13.948568 16.126242,13.948568z M7.1679735,13.948568C5.621069,13.948568 4.3685136,15.201555 4.3685131,16.74834 4.3685136,18.292325 5.621069,19.547214 7.1679735,19.547214 8.713438,19.547214 9.9674625,18.292325 9.9674625,16.74834 9.9674625,15.201555 8.713438,13.948568 7.1679735,13.948568z M0,10.684L53.755001,10.684 53.755001,51.668001 0,51.668001z M8.5679998,0L58.668022,0 64,0 64,5.6864691 64,45.317999 58.668022,45.317999 58.668022,5.6864691 8.5679998,5.6864691z" />
</Grid>
</Page>
Then put the PathGeometry data (string of the node "Figures") to the value of inside "Data":
Next, you need to click "Auto Parse" button in left top postion, you can view the rendering result (red border region in screenshot). See below, I just use the data second one from your data.
WPF Geometry Transformation Tool
Download: WPF Geometry Transformation Tool.
Put the string of the node "Figures" into the textarea of Input Geometry, then you can see the result (red border region in screenshot).

Error when create Image file

I have a user control library that will use as a custom tooltip for another window, the user control holds ImageSource of a imagebrush that reference to a directory . Inside the window, I have another class that will generate an image file to the directory same as the imagebrush.
However i get an error below after run.
The call stack contained only external code.
'The invocation of the constructor on type 'WpfApplication2.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'
Here is my snippet.
UserControl1.xaml
<UserControl.Resources>
<Style TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<ImageBrush ImageSource="C:\Users\user\Desktop\wpf\WpfApplication2\WpfApplication2\Images/QR.png" Stretch="Fill" />
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
DisplayWindow.xaml
xmlns:myToolTip="clr-namespace:WpfControlLibrary2;assembly=WpfControlLibrary2"
<myToolTip:UserControl1 Visibility="Collapsed" x:Name="customToolTip" Width="468" Height="700" />
QRCodeEncoder.cs
public QrCodeEncodercs(string encodeString)
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
//const string encodeString = "123";
qrEncoder.TryEncode(encodeString, out qrCode);
Renderer renderer = new Renderer(11, System.Drawing.Brushes.Black, System.Drawing.Brushes.White);
renderer.CreateImageFile(qrCode.Matrix, #"C:\Users\user\Desktop\wpf\WpfApplication2\WpfApplication2\Images\QR.png\Images\QR.png",
ImageFormat.Png);
}
DisplayWindow.xaml.cs
When i run the constructor of the class above. The error mentioned above happened.
qce = new QrCodeEncodercs(videoName);
What happened actually? Any guidance? Thanks in advance.
Edit____InnerException
InnerException: System.Runtime.InteropServices.ExternalException
HResult=-2147467259
Message=A generic error occurred in GDI+.
Source=System.Drawing
ErrorCode=-2147467259
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at Gma.QrCodeNet.Encoding.Windows.Controls.Renderer.CreateImageFile(BitMatrix matrix, String fileName, ImageFormat imageFormat)
at WpfApplication2.DisplayWindow.QrCodeEncodercs(String encodeString) in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 127
at WpfApplication2.DisplayWindow.PopulateVideoListAndFirstVideo() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 157
at WpfApplication2.DisplayWindow..ctor() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\DisplayWindow..xaml.cs:line 79
at WpfApplication2.MainWindow..ctor() in c:\Users\user\Desktop\wpf\KinectREAL\WpfApplication2\WpfApplication2\MainWindow.xaml.cs:line 45
InnerException:
These Generic error in GDI+ exceptions can be cryptic at times. One cause I've experienced in the past is when an image file has an incorrect extension (eg: a JPG ssaved with a GIF extension). My second guess would be that the filename in the path of the file you're saving to is invalid. Does the directory exist?
If the file is in use, you could copy it to a temporary directory with File.Copy and get a temporary filename with Path.GetTempFilename().
I manage to solve after some trying and it works so far. Thanks again.
System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(#"C:\Users\user\Desktop\wpf\WpfApplication2\WpfApplication2\Images\QR.png", UriKind.RelativeOrAbsolute);
bi.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
bi.EndInit();
image.Source = bi;

PieChart with Labels

I want to make LabeledPieCharts in WPF (Source: Bea's Blog )
I have downloaded the DemoProject and it runs. If I want to create a LabeledPieChart it fails with this Error:
The Tag "LabeledPieChart.Series" isn't in XML-Namespace "clr-namespace:Controls;assembly=Controls". Line 65 Position 14.
Here is my code:
<customControls:LabeledPieChart x:Name="labeledPieChart"
Title="Population of Puget Sound Cities"
Grid.Row="3"
Width="700"
Height="500"
BorderBrush="Gray">
<customControls:LabeledPieChart.Series>
<customControls:LabeledPieSeries x:Name="labeledPieSeries"
DependentValuePath="Population"
IndependentValuePath="Name"
IsSelectionEnabled="True"
ItemsSource="{Binding}"
LabelDisplayMode="Auto"
PieChartLabelItemTemplate="{StaticResource pieChartLabelDataTemplate}"
PieChartLabelStyle="{StaticResource pieChartLabelStyle}" />
</customControls:LabeledPieChart.Series>
</customControls:LabeledPieChart>
I've downloaded the project and your code seems to work OK. Maybe this question will help you a bit.

Resources