在 PropertyGrid 中的对象内部编辑对象的属性
我正在尝试创建一个可使用属性网格进行配置/编辑的对象。 除了对象内的对象之外,一切都很顺利。
我有一个名为“ContactInformation”的对象/类。在该对象内,我有一个名为“Correspondence”的对象。
这就是该部分的外观:
[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 键,或单击其他位置时,它不会保留我刚刚输入的值,而是会变回来。
有人知道为什么会发生这种情况吗?或者也许是在属性网格中的对象中显示对象属性的更好主意?
I'm trying to make an object, configureable/editable with a propertygrid.
This is all going well, except for objects inside objects.
I've got an object/class named "ContactInformation". And inside that object I've got an object named "Correspondence".
This is how that part looks:
[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; }
}
That way I can show the properties/variables of the object inside the object, in the propertygrid.
Anyway, when I edit the values now, and press enter, or click somewhere else, instead of keeping it the value I just typed in, it changes back..
Anyone got an idea why this is happening? Or maybe a better idea to show the properties of objects in objects in the propertygrid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要编辑对象内部的属性(例如,您在 winform 编辑器中看到的内容,具有“字体”或“填充”等属性,...您可以在其中单击“加号”图标“展开”对象),您可以使用ExpandableObjectConverter 类,如下所示:
并删除当然是可浏览的(假):
To edit properties inside an object (this is what you see for example with the winform editor with properties like Font, or Padding, ... where you can "expand" the oject clicking on the 'plus' icon) , you can use the ExpandableObjectConverter class, like this:
and remove the Browsable(false) of course: