Search code examples
wpfxamltoolkitxceed

Select Editor in Extended WPF Toolkit PropertyGrid


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


Solution

  • 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>