Property Grid Extended String Property Editor with MVVM

Grids for WPF Forum

Posted 1 month ago by Jamie Godbout - Owner, Godbout PCS LLC
Version: 24.1.1
Avatar

Hello,

I am trying to set up a property grid where one my properties is a collection and I would like to use the ExtendedStringPropertyEditor to display a custom popup dialog. The available sample I found binds the ButtomCommand to some code in the code behind. However, I am using an MVVM architecture and I cannot bind the ButtonCommand to my command in my view model. I suspect that the ButtonCommmand isn't a dependancy property that can bind to the relay command in my VM.

Do you have an example of a property grid using the extendedstringPropertyEditor where the ... button can execute a command from a viewmodel using a binding?

Thanks

Jamie

Jamie Godbout

Comments (3)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jamie,

As you suspected, PropertyEditor-derived classes aren't dependency objects and use plain old CLR properties with INotifyPropertyChanged.  The only examples of using ExtendedStringPropertyEditor are in the PropertyGridPropertyDialog sample.

Could you provide some more detail on your object hierarchy and where the command property is, and what is being bound into the PropertyGrid?  With some additional information, we can try and make a suggestion.  Thanks!


Actipro Software Support

Posted 1 month ago by Jamie Godbout - Owner, Godbout PCS LLC
Avatar

Hi,

I found a work around by using a custome property editor and data template, however, I think the ExtendedStringPropertyEditor would be a cleaner solution.

What I was looking for is to put the ESPE in my property grid which is in my view xaml file, then when the ... button is clicked to run a relay command in my view model. My view model uses Microsoft MVVM Community Toolkit, FYI. 

In my work around, I put in a text box with the text bound to my collection name, and a button with the content = "..." and the command bound to my OpenDialogCommand() in my view model.

Jamie

Jamie Godbout

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jamie,

The problem here is that the ExtendedStringPropertyEditor's DataTemplate has to bind the command to something.  The IPropertyModels that are data contexts of each PropertyGrid row don't have any appropriate command properties to bind to.  And the DataTemplate isn't aware of any custom viewmodels in use.  That's why it binds to the ValuePropertyEditor.ButtonCommand property, which it does know about.

What you could possibly do if you still wanted to use ExtendedStringPropertyEditor would be to clone the default DataTemplate in the PropertyGrid.DefaultExtendedStringValueTemplate property and change the Button.Command binding in the template to be something on your viewmodel.  Then set that customized DataTemplate to your PropertyGrid.DefaultExtendedStringValueTemplate property.


Actipro Software Support

The latest build of this product (v24.1.2) was released 3 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.