0

The base class properties are missing when I bind this to my object:

<xctk:PropertyGrid x:Name="_propertyGrid"                           
  AutoGenerateProperties="True"                             
  HideInheritedProperties="False"
    SelectedObject="{Binding}" >
    </xctk:PropertyGrid>

Is there something else I need to add to see them? This is on the community addition - v3.0

**update - example more akin to the production code:

<TreeView Name="Containers">
<TreeView.ItemTemplate>

<HierarchicalDataTemplate DataType="{x:Type viewModels:ContainerViewModel}" ItemsSource="{Binding Children}">

<xctk:PropertyGrid
Width="250"
ShowTitle="False"
ShowSummary="False"
AutoGenerateProperties="True" 
HideInheritedProperties="False"
SelectedObject="{Binding}" 
SelectedObjectName=""
SelectedObjectTypeName="">

</xctk:PropertyGrid>


</HierarchicalDataTemplate>
</TreeView

**update - I found that when I inspect a class that has overrides of the base properties, it prevents all of the base class properties from showing up in the property grid.

Looking into this further now, but I don't have a solution.

jchristof
  • 2,794
  • 7
  • 32
  • 47

2 Answers2

2

Is there something else I need to add to see them?

Just make sure that the properties are public. The following works for me.

Code:

public class Base
{
    public int Test { get; set; }
}

public class Derived : Base
{
    public int Test2 { get; set; }
}

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }

    public Derived Derived { get; } = new Derived();
}

XAML:

<xctk:PropertyGrid x:Name="_propertyGrid"                           
                   AutoGenerateProperties="True"                             
                   HideInheritedProperties="False"
                   SelectedObject="{Binding Derived}" >
</xctk:PropertyGrid>

enter image description here

mm8
  • 163,881
  • 10
  • 57
  • 88
  • My inspected types are in a tree and displayed using TreeView and HierarchicalDataTemplate with DataType="{x:Type viewModels:ContainerViewModel}". In my scenario, I notice that inherited properties are displayed only when the inheriting type has no properties of it's own. Somewhere therein is the cause. ContainerViewModel is the base type of all the objects. – jchristof May 17 '17 at 13:07
  • I'll put together a repro - I found the issue in my case is when any inherited property is overridden none of the inherited properties show in the grid. – jchristof May 17 '17 at 19:39
-1

In my inherited overridden properties, only the set or get was provided in the property override. When I added the missing getter or setter to the overridden property it fixes the issue:

public override double Height {
    get {
    //this get is necessary for the design
    }

    //adding set is necessary for Height to be visible
    set { base.Height = value; }
}
jchristof
  • 2,794
  • 7
  • 32
  • 47