question

NaveenKumarR-7228 avatar image
NaveenKumarR-7228 asked ·

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
10 |1000 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-MSFT avatar image
DaisyTian-MSFT answered ·

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.


Share
10 |1000 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.