I create images on the fly by using the following code:
Public Function ToBitmapImage(byteArray As Byte()) As BitmapImage
Dim image As New BitmapImage()
Dim stream As New MemoryStream(byteArray)
image.BeginInit()
image.StreamSource = stream
image.EndInit()
image.Freeze()
Return image
End Function
Then I tried to clone one of the objects containing the image with the following code:
Public Function Clone(Of T As DependencyObject)(orginal As T) As T
If (orginal Is Nothing) Then
Return Nothing
End If
Using stream As New MemoryStream()
XamlWriter.Save(orginal, stream)
stream.Position = 0
Return CType(XamlReader.Load(stream), T)
End Using
End Function
The images are serialized into:
...xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation"...
<av:Image ...>
<av:Image.Source>
<av:BitmapImage BaseUri="{x:Null}" />
</av:Image.Source>
</av:Image>
The BaseUri="{x:Null}"
causes Initialization of 'System.Windows.Media.Imaging.BitmapImage' threw an exception. rownumber 1 row position xxx.
Is there any way to force it so serialize the data in the BitmapImage instead of baseUrl?