【问题标题】:PropertyGrid does not list member class membersPropertyGrid 不列出成员类成员
【发布时间】:2011-02-07 22:40:16
【问题描述】:

我有:


class Foo1
{
    private string name1;
    [CategoryAttribute("Category1")]
    public string Name1
    {
        get { return name1; }
        set { name1 = value; }
    }
}


class Foo2
{
    private string name2;
    [CategoryAttribute("Category2")]
    public string Name2
    {
        get { return name2; }
        set { name2 = value; }
    }
}

如果我从 Foo1 派生 Foo2 并将 Foo2 设置为 PropertyGrid 中的 SelectedObject,我将列出 Foo1 的成员,但如果我在 Foo2 中有 Foo1 成员,则不会列出 Foo1 成员。对于第二种情况,有没有办法在 PropertyGrid 中列出 Foo1 的成员?

谢谢!

【问题讨论】:

  • 我开始使用 C# 以简单的方式制作简单的东西。我浪费了很多时间试图理解该语言并将用 C++ 制作的东西与 C# 集成。似乎这种语言使定制(几乎)成为不可能。它对所有类都有一个糟糕的接口。感谢过去几周我在这里收到的帮助,但我将继续使用 C++。我没有看到使用 C# 的任何优势,所以我将停止使用它。

标签: c# propertygrid


【解决方案1】:

尝试为 Foo2 指定一个类型转换器。现在 Foo2 的成员应该列在 Foo1 对象的属性中。

[TypeConverter(typeof(ExpandableObjectConverter))]
class Foo2
{
    private string name2;
    [CategoryAttribute("Category2")]
    public string Name2
    {
        get { return name2; }
        set { name2 = value; }
    }
}

【讨论】:

  • 如果 Foo1 具有 Foo2 类型的属性。
【解决方案2】:

您需要类型转换器来实现这一点。看看这个:Getting the Most Out of the .NET Framework PropertyGrid Control支持自定义类型

部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    相关资源
    最近更新 更多