无法序列化 SolidColorBrush

编程入门 行业动态 更新时间:2024-10-11 03:15:58
本文介绍了无法序列化 SolidColorBrush的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法序列化类的错误消息,因为无法序列化 SolidColorBrush

Error message that I cannot serialize a class because cannot serialize SolidColorBrush

该类有一个Brush的公共属性

The class has a public property of Brush

有修复吗?

比较复杂.我尝试使用可以序列化的支持属性问题是我还需要冻结 HighLight 以便我可以在 BackgroundWorker 上创建如果我为 HighLight 使用可序列化的支持属性,则 Highlight.Freeze 失败

It is more complex. I tried using a backing property that can be serialized Problem is that I also need to Freeze the HighLight so I can be created on a BackgroundWorker If I use a serializable backing property for HighLight then Highlight.Freeze fails

[Serializable()] public class WordIdLenHightlight : Object { private string highlightHex; public Int32 ID { get; private set; } public Byte Len { get; private set; } //[NonSerialized] public Brush Highlight { get; private set; } //{ if (string.IsNullOrEmpty(highlightHex)) return null; else return new SolidColorBrush((Color)ColorConverter.ConvertFromString(highlightHex)); } public string HighlightHex { get { return highlightHex; } } public override bool Equals(Object obj) { // Check for null values and compare run-time types. if (obj == null) return false; if (!(obj is WordIdLenHightlight)) return false; WordIdLenHightlight comp = (WordIdLenHightlight)obj; return (comp.ID == this.ID); } public override int GetHashCode() { return ID; } public WordIdLenHightlight(WordIdLenHightlight w) { ID = w.ID; Len = w.Len; Highlight = w.Highlight; highlightHex = w.Highlight.ToString(); Highlight.Freeze(); } public WordIdLenHightlight(Int32 id, byte len, Brush highlight) { ID = id; Len = len; Highlight = highlight; //highlightHex = Highlight.ToString(); Highlight.Freeze(); } public WordIdLenHightlight(Int32 id, byte len, string HighlightHex) { highlightHex = HighlightHex; ID = id; Len = len; Highlight = new SolidColorBrush((Color)ColorConverter.ConvertFromString(highlightHex)); Highlight.Freeze(); } }

推荐答案

你不说你是如何序列化这个类的,但你可能可以通过以下方式来装饰 Brush 属性或其支持字段一个属性,例如 NonSerialized 或 XmlIgnore.

You don't say how you're serializing the class, but you can probably decorate the Brush property or its backing field by an attribute such as NonSerialized or XmlIgnore.

您可能想要序列化一些其他信息,而不是使您能够在反序列化时重建 Brush,例如,它的颜色.

You might want to serialize some other information than enables you to reconstruct the Brush on deserialization, for example, its color.

更多推荐

无法序列化 SolidColorBrush

本文发布于:2023-11-12 13:10:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   SolidColorBrush

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!