在 PropertyGrid 中实现子字段
好吧,我的 C# 术语不太好,所以我将尝试用一个小例子来解释这一点。如果您创建一个在 PropertyGrid 中使用的类,并且您具有以下值:
class Test
{
public Point example { get; set; }
}
这将生成一个 PropertyGrid,它具有一个可扩展对象“example”,该对象具有字段 X 和 Y 以创建“Point”。
我正在尝试创建一个对象“name”,其中包含字段“firstname”和“lastname”,所以我有:
class Test
{
public Name example { get; set; }
}
public struct Name
{
public string firstname { get; set; }
public string lastname { get; set; }
}
但这并没有按预期工作。
我认为我需要重写一些方法才能使其正常工作,但是由于我实际上没有 PropertyGrid 的术语,因此我很难找到解决方案。
任何帮助都会很棒。
Alright so my terminology when it comes to C# isn't great, so I'll attempt to explain this with a small example. If you create a class which you are using within a PropertyGrid and you have the following values:
class Test
{
public Point example { get; set; }
}
This will produce a PropertyGrid which has an expandable object "example" which has fields X and Y in order to create a "Point".
I'm attempting to create an object "name" which has fields "firstname" and "lastname", so I have:
class Test
{
public Name example { get; set; }
}
public struct Name
{
public string firstname { get; set; }
public string lastname { get; set; }
}
This however isn't working as intended.
I think I need to override some method(s) in order to get this working, however since I don't really have the terminology down for PropertyGrids it is difficult for me to find a solution.
Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量查找后,我终于弄清楚了,缺少的关键字是“ExpandableObjectConverter”。
不管怎样,这里是示例代码:
PropertyGrids 确实令人困惑。
After a lot of looking around I finally was able to figure it out, the missing keyword was "ExpandableObjectConverter."
Anyway, here is example code:
PropertyGrids sure are confusing.
我相信在这种情况下,自动实现的属性定义
不适用于结构类型,但适用于类类型。在第一个示例中,
Point
是一个类类型。尝试
一下
可能会起作用。
I believe that in this instance auto-Implimented property definitions
don't work for struct types but class types. In the first example
Point
is a class type.Try
then
may work.