PropertyGrid 中的自定义属性名称?
我有一个在 PropertyGrid
中使用的类。我发现,通过在每个属性上设置 CategoryAttribute
,它显然会为每个项目创建一个新类别。这将我的属性网格设置为每个包含我的自定义名称的项目都有一个 [+],这不是我想要实现的行为。
在 Visual Studio 中,如果单击解决方案资源管理器中的某个项目(例如程序集),它具有零个树节点和一个完美命名的属性列表,即任何字符串都可以标识属性,而不仅仅是对象的名称。因此,不要这样:
[+ 文件路径]
文件路径 |属性值
[+ 文件大小]
文件大小 | 0 KB
我正在寻找这个:
[+ 文件]
文件路径 |值
文件大小 | 0 KB
或者甚至上面没有初始 [+] 节点。我已经通过 System.ComponentModel 命名空间寻找适用的属性,但我找不到。
我怎样才能达到这个效果?这一定是可能的,Visual Studio 做到了,我相信它们是同一个组件,而不是派生和扩展的组件。
I have a class that I use in a PropertyGrid
. I found that by setting CategoryAttribute
on each property it creates a new category for each item, obviously. This sets my property grid to have a [+] for each item with my custom name in it, and this isn't the behavior I'm trying to achieve.
In Visual Studio, if you click on an item in the Solution Explorer, say, an assembly, it has zero tree nodes and just a list of perfectly-named properties, i.e. any string can identify a property, not just the object's name. So instead of having this:
[+ File Path]
FilePath | propertyValue
[+ File Size]
FileSize | 0 KB
I'm looking for this:
[+ File]
File Path | value
File Size | 0 KB
Or even the above without the initial [+] node. I've poured through the System.ComponentModel namespace looking for an applicable attribute but I can't find one.
How can I achieve this effect? It must be possible, Visual Studio does it and I believe they're the same component, not a derived and extended one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 DisplayNameAttribute 更改显示的文本(使其更易于阅读),DescriptionAttribute 添加帮助文本属性,以及对属性进行分组的 CategoryAttribute ..
Use the DisplayNameAttribute to change what text displays (make it more human readable), the DescriptionAttribute to add help text to the property, and the CategoryAttribute to group the properties..
您需要将 CategoryAttribute 设置为“文件”对于这两个属性:
我建议阅读“充分利用 .NET 属性网格Control”了解可用于组织属性的其他想法,包括添加说明。
You'll want to have CategoryAttribute set to "File" for BOTH properties:
I recommend reading "Getting the most out of the .NET Property Grid Control" for other ideas you can use for organizing your properties, including adding descriptions.