【问题标题】:Propertygrid in netcoreappnetcoreapp 中的 Propertygrid
【发布时间】:2020-05-02 17:04:33
【问题描述】:

我以前可以在 Net472 中执行此操作,但当我尝试在 Netcoreapp3.1 中执行此操作时遇到错误

enter code here
        BrowsableAttribute theDescriptorBrowsableAttribute = (BrowsableAttribute)theDescriptor.Attributes[typeof(BrowsableAttribute)];
        FieldInfo browsablility = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);

        // Set the Descriptor's "Browsable" Attribute
        browsablility.SetValue(theDescriptorBrowsableAttribute, isBrowsable);

browsablility 返回 null。它现在似乎是 OnInitOnly 并且无法设置。

有什么想法吗?我只想根据属性使项目可见或不可见。

【问题讨论】:

  • 您的代码依赖于一个名为“browsable”的私有字段,该字段可能已经消失。你为什么不直接使用BrowsableAttribute.Browsable公共财产?
  • 可浏览是只读的,不能更改。

标签: propertygrid netcoreapp3.1


【解决方案1】:

我最终通过创建自定义属性并将该属性设置为 true 或 false 来解决问题。并将该自定义属性分配给propertgird.BrowsableAttribute

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    相关资源
    最近更新 更多