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
|
While I understand the motives for separating business objects from presentation details, I'm left wondering how I go about transitioning the large amount of code I have written in support of the old PropertyGrid.
For example, I have editors defined that inherit from UITypeEditor.
Is there a way for me to hook those editors into your grid, even if have to do it programmatically?
Your grid looks great, and I want it in our product!
Thanks and regards
Dave D
|
|
|
Hello Dave, I would start with this article: http://www.mindscape.co.nz/blog/index.php/2008/12/11/smart-editors-for-the-wpf-property-grid-meet-smart-templates/ My approach would be: Create a WPF user control or custom control whose job it is to host Windows Forms editors via a WindowsFormsHost. This would need to have a two-way data-bindable property named something like EditedValue. Within the control, you would call UITypeEditor.EditValue, passing EditedValue as the input, and copying the return value back into EditedValue. You would probably also need another bindable property of type Node, representing the property being edited (from which your control will be able to get the EditorAttribute and hence the UITypeEditor -- you can get this via Node.Property.Attributes or Node.PropertyInfo.GetCustomAttributes if you're not concerned about partial trust). Create a smart editor that looks for the EditorAttribute, as described in the article. Create a data template that consists of your control from the first step. Set the EditedValue property to {Binding Value}. Set the Node property to {Binding Property}. Associate this with the smart editor. Some issues that you may run into: * How to handle inline and drop-down editors? In Windows Forms, the WinForms grid knows when to call UITypeEditor.EditValue, but you will need to handle this yourself in order to translate between the WPF world of the declarative EditedValue binding and the procedural world of the UITypeEditor.EditValue command. * The dreaded IServiceProvider. From my limited experience of build WinForms editors, you will at minimum need to provide an IWindowsFormsEditorService. We don't provide this, so your custom control will need to do so manually. * You might find it easier to create three Windows Forms controls, one for inline, one for drop-down and one for dialog, and three data templates, then select between the templates according to the result of UITypeEditor.GetEditStyle. You can do this in your smart editor by providing three template properties on the editor type, and making SetContentTemplate choose between them (SetContentTemplate gets a Node so it can get at the EditorAttribute), or by using an intermediate DataTemplate containing a ContentControl with ContentTemplateSelector set to a suitable DataTemplateSelector. Hope this helps! |
|