【问题标题】:Providing values to enum properties generated at runtime for propertygrid为运行时为 propertygrid 生成的枚举属性提供值
【发布时间】:2013-08-15 08:39:21
【问题描述】:

我需要在运行时添加枚举属性以显示在 proertygrid 中,这将我带到这个页面

Properties generated at runtime (PropertyGrid.SelectedObject)

它完成了我想要的工作。我使用静态枚举对此进行了测试,但我还需要在运行时向枚举提供用户定义的值。我明白我需要更改

 public override StandardValuesCollection
             GetStandardValues(ITypeDescriptorContext context)

方法,但问题是 context.instance 属性显示了提到的stackoverflow页面中描述的包内的所有属性。因此,如果我有 5 个属性,则实例属性将具有 5 个属性的数组;我怎样才能找出我应该弄乱哪一个?除了在 GetStandardValues() 方法中填充它之外,还有其他方法可以向枚举提供值吗?

干杯, ES

【问题讨论】:

    标签: c# reflection properties propertygrid


    【解决方案1】:

    ITypeDescriptorContext 对象有一个 PropertyDescriptor.Name 属性

    context.PropertyDescriptor.Name
    

    这将显示元素。

    -ES

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多