2

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

Carlos
  • 1,638
  • 5
  • 21
  • 39
  • 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 Jan 03 '17 at 12:40
  • 1
    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 Jan 04 '17 at 16:10

1 Answers1

2

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>
John Cummings
  • 1,949
  • 3
  • 22
  • 38
  • Yes, this is the right approach, although your code is wrong. You cannot put a EditorTemplateDefinition inside a PropertyDefinition (it must be outside, in a EditorDefinitions label). There must be two different blocks in PropertyGrid: EditorDefinitions and PropertyDefinitions. If you fix it, I will mark your answer as the accepted one. Thank you – Carlos Jul 25 '18 at 16:06
  • Good catch. I'm not sure why I had the other code there. In any case, I have updated it. – John Cummings Jul 26 '18 at 14:40