question

NaveenKumarR-7228 avatar image
0 Votes"
NaveenKumarR-7228 asked DaisyTian-1203 edited

XamlWriter image serialization isssue (InvalidOperationException: Property 'UriSource' or property 'StreamSource' must be set.)

Hi,

i am using a ink canvas and added a image to it and then serialize using XamlWriter.

Image img = new Image();
BitmapImage img = NImageHelper.GetBitmapImageFromString(ImageData, new Size(src.Width, src.Height));
img.Source = img;

string Xml = XamlWriter.Save(myCanvas);

this code works fine, Here is the xml generated

<Image Height="100" Width ="150">
<Image.Source>
<BitmapImage CacheOption="None" CreateOptions="IgnoreImageCache" BaseUri="{x:Null}"/>
</Image.Source>
</Image>

in this xml bitmapimage's StreamSource property is not serialized


When i try to parse it back it is throwing exception

System.Windows.Markup.XamlParseException: ''Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception.'
InvalidOperationException: Property 'UriSource' or property 'StreamSource' must be set.


It works fine if the bitmapimage's UriSource property is set and i am able to parse it back.

Please help me , how to serialize StreamSource property?

Thanks in advance.

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered DaisyTian-1203 edited

Welcome to our Microsoft Q&A platform!

You can set UriSource = "" for BitMapImage or not set Image.Source in the XAML, then set the image source in the cs.You can refer to the examples in the document for showing the picture.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.