如何序列化GridLength作为用户设置的一部分
本文关键字:用户 设置 一部分 序列化 GridLength | 更新日期: 2023-09-27 18:02:58
我有一个自定义类型,它有几个GridLength
属性。此类型是用户设置的一部分。保存设置后,我的设置文件看起来像这样:
<MavEditor xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RightSideWidth />
<LeftSideWidth />
<BottomSideHeight />
其中RightSideWidth
、LeftSideWidth
、BottomSideHeight
为GridLength
。
在保存设置之前,我知道它们的值不是Auto
,但看起来XML序列化器忽略了这个事实。
我做错了什么?
我使用这个快速而肮脏的解决方案。可以,但可能导致性能问题。
public GridLength Height
{
// Create the "GridLength" from the separate properties
get => new GridLength(this.Height_Value, (GridUnitType)Enum.Parse(typeof(GridUnitType), this.Height_GridUnitType));
set
{
// store the "GridLength" properties in separate properties
this.Height_GridUnitType = value.GridUnitType.ToString();
this.Height_Value = value.Value;
}
}
public string Height_GridUnitType { get; set; }
public double Height_Value{ get; set; }