HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

Subclassing PropertyGrid breaks its functionality

Open SamirKharchi opened this issue 4 years ago • 2 comments

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

SamirKharchi avatar May 06 '21 11:05 SamirKharchi

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}"/>

SamirKharchi avatar Jul 01 '21 08:07 SamirKharchi

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>

Deliay avatar May 30 '23 18:05 Deliay