How Do I Choose an Editor at Runtime?
You may want to choose an editor at runtime when:
- You do not know the names of properties until you load them. (This is common when using ItemsSource instead of SelectedObject.)
- There are runtime conditions which affect the choice of editor. (For example certain properties should be displayed as read-only to users without the Supervisor privilege.)
The three main options are:
- As you build the dictionary that will become the ItemsSource, add editors to the Editors collection programmatically.
- Put the logic into a DataTemplateSelector or a trigger.
- Create a smart editor declaration (a subclass of Editor with a custom CanEdit override).
For more information about these options and how to implement them, see Choosing WPF Property Grid editors from code on the Mindscape blog.