Eri*_*ith 20 c# propertygrid winforms
我有一个课,我在一个PropertyGrid.我发现通过设置CategoryAttribute每个属性,它显然为每个项目创建了一个新类别.这将我的属性网格设置为每个项目都有一个[+],其中包含我的自定义名称,这不是我想要实现的行为.
在Visual Studio中,如果单击解决方案资源管理器中的项目(例如,程序集),它将具有零树节点和仅有完美命名属性的列表,即任何字符串都可以标识属性,而不仅仅是对象的名称.所以不要这样:
[+文件路径]
FilePath | propertyValue
[+ File Size]
FileSize | 0 KB
我在找这个:
[+文件]
文件路径| 值
文件大小| 0 KB
甚至上面没有初始的[+]节点.我已经通过System.ComponentModel命名空间寻找适用的属性,但我找不到.
我怎样才能达到这个效果?它必须是可能的,Visual Studio会这样做,我相信它们是相同的组件,而不是派生和扩展的组件.
Tom*_*son 42
使用DisplayNameAttribute更改显示的文本(使其更易于阅读),使用DescriptionAttribute向属性添加帮助文本,使用CategoryAttribute对属性进行分组.
using System.ComponentModel;
[Category("Test")]
[DisplayName("Test Property")]
[Description("This is the description that shows up")]
public string TestProperty {get;set;}
Run Code Online (Sandbox Code Playgroud)
您希望将CategoryAttribute设置为BOTH属性的"File":
[Category("File")]
public string FilePath { get; set;}
[Category("File")]
public int FileSize { get; set;}
Run Code Online (Sandbox Code Playgroud)
我建议阅读" 充分利用.NET Property Grid Control ",了解可用于组织属性的其他想法,包括添加说明.
| 归档时间: |
|
| 查看次数: |
13508 次 |
| 最近记录: |