你如何控制哪些在运行时属性网格是可见的? [英] How do you control what is visible in a property grid at runtime?

查看:238
本文介绍了你如何控制哪些在运行时属性网格是可见的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性网格显示列表,例如一类

I have a property grid displaying a list, for example of a class Person

[TypeConverter(typeof(ExpandableObjectConverter))]
public class Person
{
    public bool ShowHidden { get; set; }
    public string Name { get; set; }
    //[Browsable(false)]
    public string Hidden { get; set; }

    public override string ToString()
    {
        return string.Format("Person({0})", Name);
    }
}



现在的问题是我怎么控制可浏览()在运行时的属性,这样当 ShowHidden = FALSE 隐藏线(以下高亮黄色)省略。

The question is how do I control the Browsable() attribute at runtime such that when ShowHidden = false the Hidden line (highlighted yellow below) is omitted.

感谢

推荐答案

下面是一个例子:

PropertyDescriptor descriptor=
  TypeDescriptor.GetProperties(this.GetType())["DataType"];
BrowsableAttribute attrib= 
  (BrowsableAttribute)descriptor.Attributes[typeof(BrowsableAttribute)]; 
FieldInfo isBrow = 
  attrib.GetType().GetField("browsable",BindingFlags.NonPublic | BindingFlags.Instance);
isBrow.SetValue(attrib,false);



只需更换数据类型与您的属性名称。
注意,所有属性必须被更改属性(在这种情况下,可在线浏览)。从这里采取了一个属性缺少类属性的属性,所有获得新的属性设置

Just replace DataType with your property name. Note, all properties must have the attribute being changed (in this case, Browsable). If one of the properties is missing the attribute, all of the class properties get the new attribute setting.

代码:<一HREF =http://www.codeproject.com/Tips/48015/Exploring-the-Behaviour-of-Property-Grid相对=nofollow>探索属性网格的行为。

这篇关于你如何控制哪些在运行时属性网格是可见的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆