2
votes

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
I'm not really sure I understand your question but I think that setting the model of the control specifically could solve your problem (you keep the model of the entire view and just change the one from the affected control). - Nahuel Ianni
I mean a way to specify an editor from XAML, so I do not have to specify it in C# with an attribute. Thank you - Carlos

1 Answers

2
votes

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>