在PropertyGrid中编辑对象内部对象的属性
本文关键字:内部对象 属性 对象 编辑 PropertyGrid | 更新日期: 2023-09-27 17:59:12
我正在尝试创建一个对象,该对象可以使用属性网格进行配置/编辑。这一切都很顺利,除了物体内部的物体。
我有一个名为"ContactInformation"的对象/类。在这个物体里面,我有一个物体,叫做"对应"。
这就是这个部分的样子:
[Browsable(false)]
public Correspondence Correspondence
{
get;
set;
}
public int CorrespondenceStatus
{
get { return this.Correspondence.Status; }
set { this.Correspondence.Status = CorrespondenceStatus; }
}
public string CorrespondenceComment
{
get { return this.Correspondence.Comment; }
set { this.Correspondence.Comment = CorrespondenceComment; }
}
public DateTime CorrespondenceDate
{
get { return this.Correspondence.LastSend; }
set { this.Correspondence.LastSend = CorrespondenceDate; }
}
这样,我就可以在属性网格中显示对象内部对象的属性/变量。
不管怎样,当我现在编辑这些值,然后按enter键,或者单击其他地方时,它不会保持我刚才输入的值,而是变回了。。
有人知道为什么会发生这种事吗?或者在属性网格中显示对象中对象的属性是一个更好的主意?
要编辑对象内部的属性(这就是您在winform编辑器中看到的,该编辑器具有Font或Padding等属性……单击"加号"图标可以"展开"项目),您可以使用ExpandableObjectConverter类,如下所示:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Correspondence
{
...
}
并删除可浏览(错误)当然:
public Correspondence Correspondence
{
get;
set;
}