У меня есть класс PGMain в качестве SelectedObject в сетке свойств :
[DefaultPropertyAttribute("Basic")]
[Serializable]
public class PGMain
{
private TestClass m_TEST = new TestClass();
[CategoryAttribute("TEST")]
public TestClass TEST
{
get { return m_TEST; }
set { m_TEST = value; }
}
// More members are here
}
Теперь я хотел бы расширить члены TestClass в PropertyGrid.Поэтому я попробовал следующее:
[Serializable]
[DescriptionAttribute("Expand to see the options for the application.")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class TestClass : ExpandableObjectConverter
{
[CategoryAttribute("test-cat"), DescriptionAttribute("desc")]
public string Name = "";
[CategoryAttribute("test-cat"), DescriptionAttribute("desc")]
public object Value = null;
[CategoryAttribute("test-cat"), DescriptionAttribute("desc")]
public bool Include = true;
public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType)
{
if (destinationType == typeof(TestClass))
return true;
return base.CanConvertTo(context, destinationType);
}
}
В результате перед значком TestClass в таблице свойств есть значок расширения, но его нельзя развернуть.Что мне не хватает?Просто для ясности: я могу показывать расширяемые члены класса PGMain, но НЕ расширяемые члены членов класса PGMain, такие как Test-member в PGMain.
Редактировать:
Нет, у меня есть 2 класса НЕ 1.
[DefaultPropertyAttribute("Basic")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class fooA
{
private fooB m_TestMember = new fooB();
[Browsable(true)]
[CategoryAttribute("Test category"), DescriptionAttribute("desctiption here")] // <<<<< this one works.
[TypeConverter(typeof(fooB))]
public fooB TestMember
{
get { return m_TestMember; }
set { m_TestMember = value; }
}
}
[DefaultPropertyAttribute("Basic")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class fooB
{
private string m_ShowThisMemberInGrid = "it works"; // <<<<< this doesn NOT work
[CategoryAttribute("Tile"), DescriptionAttribute("desctiption here")]
public string ShowThisMemberInGrid
{
get { return m_ShowThisMemberInGrid; }
set { m_ShowThisMemberInGrid = value; }
}
public override string ToString()
{
return "foo B";
}
}
Но я решил проблему (по стечению обстоятельств).Похоже, что публичные переменные не перечислены в таблице свойств.Это должны быть свойства с геттерами и сеттерами.Это было решение.Таким образом, приведенный выше фрагмент решил проблему.В любом случае, спасибо за ваши ответы:).