Select Editor in Extended WPF Toolkit PropertyGrid

1.2k views Asked by At

Using PropertyGrid from Extended WPF Toolkit. I would like to select a built-in editor for a field.

I know I can get it from the model, this way:

[Editor(typeof(TextBoxEditor), typeof(TextBoxEditor))]
public string LastName { get; set; }

But I would like to get it from XAML, something like this (of course it is NOT valid):

<xctk:PropertyGrid.PropertyDefinitions>
    <xctk:PropertyDefinition TargetProperties="PetNames" Editor="TextBoxEditor" />
</xctk:PropertyGrid.PropertyDefinitions>

Is there a way to show a property in a not-default editor, without changing my model?

Thank you

1

There are 1 answers

2
John Cummings On BEST ANSWER

As mentioned, in the documentation, you may create a custom editor using DataTemplates by setting the EditingTemplate like so:

<xctk:PropertyGrid.EditorDefinitions>
    <xctk:EditorTemplateDefinition TargetProperties="PetNames">
        <xctk:EditorTemplateDefinition.EditingTemplate>
            <DataTemplate>
                <!-- put whatever control you would like here (including your own custom one) -->
                <TextBox Text="{Binding Value}" />
            </DataTemplate>
        </xctk:EditorTemplateDefinition.EditingTemplate>
    </xctk:EditorTemplateDefinition>
</xctk:PropertyGrid.EditorDefinitions>