XamlWriter 的 C# 对象 Xaml 工厂方法

发布于 2024-10-10 11:23:01 字数 779 浏览 0 评论 0原文

我的类使用图像作为属性(public Image myImage)。当此类被序列化 (XamlWriter) 时,它工作正常,读回它会出现异常:

'在类型上找不到匹配的构造函数 '系统.绘图.位图'。您可以使用 参数或工厂方法 构造这种类型的指令。 行号“5”和行位置“8”。

显然,以 ColorPalette 作为参数的位图缺少一个构造函数:

<sd:Bitmap>
  <sd:Bitmap.Palette>
    <sdi:ColorPalette /> 
  </sd:Bitmap.Palette>
</sd:Bitmap>

我知道我可以指定一个以某种方式创建位图的工厂方法。我还找到了一些有关此指令的文章,例如 http://www.wpftutorial.net/XAML2009.html< /a>

但是,我不是 Xaml 方面的专家,并且不了解如何以及在何处定义/声明我的属性上的方法。不幸的是我也没有找到这方面的例子。

我期待一些类似的

[FactoryMethod("XYZ")]
public Image myImage ....

但实际上什么也没发现。你知道什么想法/例子吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文