Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: PropertyGrid edit defaults editors

$
0
0
I also had the same problem. I wanted to extend the default editors without declaring a new templatedefinition for each editors.
I came with this solution, it isn't pretty and not yet fully tested but it seems to work. It the same idea as your ResolveEditor.

This is the template I use in my property grid
<xwt:EditorTemplateDefinition TargetProperties="{x:Static local:EditorProxy.Types}">
                    <xwt:EditorTemplateDefinition.EditingTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                
                                <local:EditorProxy Grid.Column="0" Value="{Binding Value}" />                                
                                <local:UnitDisplay Grid.Column="1" PropertyDescriptor="{Binding PropertyDescriptor}"                               
                                   Margin="15,0,15,0"/>
                            </Grid>
                        </DataTemplate>
                    </xwt:EditorTemplateDefinition.EditingTemplate>
                </xwt:EditorTemplateDefinition>
You can see that I don't target only one type. local:EditorProxy is a static property that list all the type that I want to support.

local:EditorProxy is were the magic happen. It loads the correct default editor based on the type of the value.

I'll not go into full detail but basically this is how it works :
  • Value is a dependency property, I bind it like the defaults editors
  • I check the type of the binded property in the binding
  • I instantiate the correct default editor based on this type
  • I create a new binding between the property and the editor I just instantiated
  • I delete the binding between the property and the EditorProxy as it's now useless.
I hope it'll help you.

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>