My class uses an image as Property (public Image myImage
). When this class is serialized (XamlWriter
) it works fine, reading it back gives an exception:
'No matching constructor found on type 'System.Drawing.Bitmap'. You can use the Arguments or FactoryMethod directives to construct this type.' Line number '5' and line position '8'.
Obviously there is a constructor missing for Bitmap with ColorPalette as argument:
<sd:Bitmap>
<sd:Bitmap.Palette>
<sdi:ColorPalette />
</sd:Bitmap.Palette>
</sd:Bitmap>
I understand that I can specify a factory method creating the bitmap somehow. I also found some articles about directives for this such as http://www.wpftutorial.net/XAML2009.html
However, I am not an expert in Xaml
and do not understand how and where to define / declare the method on my attribute. Unfortunately i do also not find an example for this.
I expect some like
[FactoryMethod("XYZ")]
public Image myImage ....
but actually have found nothing. Any idea / example you know?