Question

I'm using Extended WPF toolkit PropertyGrid to let users fill configurations in my application.

Everything works fine except when I try to include an ExpandableObject attribute to add a nested class.

Here is an example:

public class TestClassConfig
{
   public string ExcelName { get; set; }

   public string ResultFolder { get; set; }

   [ExpandableObject]
   public ExpandableTest OtherClass { get; set; }
}

public class ExpandableTest
{
   public string Test1 { get; set; }
   public string Test2 { get; set; }
}

I can't post an image of the result (first post), so i'll describe it: the "OtherClass" property appears but I can't see the nested class properties (Test1 and Test2) so cannot edit it.

In the PropertyGrid Documentation, it says for the property with ExpandableObject attribute that "This property is a complex property and has no default editor."

Does it means I have to create a custom Editor everytime I want to add a nested class to my property grid ?

Thanks for your answers!

No correct solution

OTHER TIPS

So, It's will be rather usefull to know how you bind it in xaml. I do it like this:

public class TestClassConfig
{
   [Category("Cat1")]
   public string ExcelName { get; set; }

   [Category("Cat1")]
   public string ResultFolder { get; set; }

   [Category("CatWithExpandObj")]
   [ExpandableObject]
   public ExpandableTest OtherClass { get; set; }
}

public class ExpandableTest
{
   public string Test1 { get; set; }
   public string Test2 { get; set; }
}

And in xaml you mast bind Selected object:

<xctk:PropertyGrid SelectedObject="{Binding TestClassConfig}"/>

I know it is a late answer, however, make sure the value of the property is not null. In other words, write something like this:

public class TestClassConfig
{
  [Category("CatWithExpandObj")]
  [ExpandableObject]
   public ExpandableTest OtherClass { get; set; } = new ExpandableTest();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top