Subclassing PropertyGrid breaks its functionality
Describe the bug Subclassing from PropertyGrid renders it non-functional. Nothing is drawn anymore.
To Reproduce
public class MyPropertyGrid : PropertyGrid {}
<myhc:MyPropertyGrid SelectedObject="{Binding SelectedObj}"/>
Expected behavior Subclassing should not change anything.
- .net 5.0
- vs2019 latest
- Version 3.1.0
The suggestion for a possible fix (or at least improvement) would be to decouple the ControlTemplate in the PropertyGridBaseStyle.xaml resource and only reference that resource in the type-targetted style, so it can be provided for derived classes.
<ControlTemplate x:Key="PropertyGridControlTemplate">
[...]
</ControlTemplate>
<Style x:Key="PropertyGridBaseStyle" TargetType="{x:Type hc:PropertyGrid}">
[...]
<Setter Property="Template" Value="{StaticResource PropertyGridControlTemplate}"/>
</Style>
Then derived PropertyGrid classes can add their own styling definition to provide the ControlTemplate:
<Style BasedOn="{StaticResource PropertyGridBaseStyle}" TargetType="{x:Type MyDerivedPropertyGrid}"/>
Add resource dictionaries of HandyContol and the style to subclass type into application's ResourceDictionary can resolve subclassing issue
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="~">
<ResourceDictionary.MergedDictionaries>
<hc:ThemeResources/>
<hc:Theme/>
</ResourceDictionary.MergedDictionaries>
<Style BasedOn="{StaticResource PropertyGridBaseStyle}" TargetType="local:KvPropertyGrid"/>
</ResourceDictionary>