This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Would it be possible to add a property editor programmatically? Scenario: I have an xml file that defines the properties of an object. This file is loaded into an observable dictionary and becomes the itemsource on the grid. I want any item in the file (and hence any property in the grid) with the word "image" in its name to use my imageproperty editor. Can't use types because this is loading from an itemsource, but I could parse the name and add the editor objects to the propertygrid.editors collection on the fly... I would also like to have any property with the word "date" to use the built-in DateEditorKey template... |
|
|
Absolutely. The code goes something like this: PropertyEditor editor = new PropertyEditor(); |
|
|
...and how about for the built-in Editor template DateEditorKey?
|
|
|
editor.EditorTemplate = (DataTemplate)(grid.FindResource(PropertyGrid.DateEditorKey)); |
|
|
By the way, I worked out another way you could accomplish this, and have posted about it at http://www.mindscape.co.nz/blog/index.php/2008/04/30/smart-editor-declarations-in-the-wpf-property-grid/. Not suggesting you throw away your working solution, of course, but you may find it a useful technique for the future. (And I hope you don't mind me using you as an example.) |
|
|
You, my boss, my priest, the local cops...everyone wants to make an example of me...
|
|
|
Ivan, I have read your blog and a small question came to mind: Considering the built-in property grid (winforms) has a feature which uses the EditorAttribute on a property to specify what kind of editor is opened, is it not possible to do this in the WPF property grid as well without extra end-user coding? Thanks for the help Ruskin |
|
|
We deliberately chose not to implement this because we believe business objects should not be taking dependencies on their UI representations. This is consistent with the usual WPF practice where the UI describes the presentation (through templates etc.), allowing the model to remain pure data and to support multiple presentations. Furthermore, we can't actually use EditorAttribute itself, because this specifies a type name, whereas what the WPF grid needs is a DataTemplate. We could of course have created a custom attribute to hold a DataTemplate name/key, but that in turn brings in some issues about where to look for the data template (by no means insoluble, but it all takes time *grin*). Of course it is possible for you to do this in your own code, and to create a smart editor to consume the attribute. This would be as described in the blog post but setting ContentTemplateProperty to be the DataTemplate obtained from looking up the attribute key rather than to be the EditorTemplate. Yes, this does mean extra end-user coding, but as I say, we'd tend to discourage it anyway, because it ties your data model to specific presentations, so we're not planning to provide a canned implementation. Hope this makes sense! |
|
|
Great, that clears the whole concept up pretty well. Cheers for that. |
|