Change/Refresh ValueTemplateKey

Grids for WPF Forum

Posted 11 years ago by Todd Larson
Version: 13.1.0580
Avatar

Using the Winforms PropertyGrid Functionality example, I'm creating a custom image and context menu in the name block.  I'm trying to figure out how to change the property editor based on what is selected in the context menu.  Say that "Apply Data Binding..." is selected... then I'd want to change the ValueTemplateKey to use my custom data binding editor.  If "Reset" is selected, then I'd want to revert back to the default ValueTemplateKey.  I can't figure out what notifications to raise so that the editor is switched on the fly.  This concept is similar to the way the VS propery inspector works.  I'm using a custom TypeDescriptorFactory and custom PropertyDataAccessor.

Thoughts?

Comments (3)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Todd,

Changing the ValueTemplateKey of the PropertyEditor is not really supported, atleast not in regards of updating the UI immediately. You could accomplish that by customizing the PropertyGrid.ValueCellContainerStyle to change the DataTemplate used based on custom triggers. The DataTemplate can also use triggers to switch what it displays, but the style approach would probably be cleaner.

If you use triggers, then you'd need a property that could be used to set the "mode" (i.e. standard entry, setting a binding, etc). This could be an attached property set on the associated PropertyGridDataAccessorItem or a property the underlying data accessor (or even your own abstraction layer). So the context menu would set the "trigger" property, and the Style would switch up the DataTemplate based on the current value.

One thing to consider if you are trying to replicate the Visual Studio PropertyGrid. When using StaticResource, the "source" information is lost once you set the value. For example, if you were to set the TextBox.Text property to "{StaticResource MyString}", then TextBox would have the string value and you would not be able to determine were it came from. This is the reason I mention building your abstraction layer that can retain this information.


Actipro Software Support

Posted 11 years ago by Todd Larson
Avatar

Do you publish the default PropertyGrid.ValueCellContainerStyle anywhere?  Note that I am using the trial version trying to prove a concept before we purchase.

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Todd,

If you are a WPF Studio customer you can download the default styles/templates at any time.  Or since you are evaluating right now, you can email our support address and we can send you the Style for that container.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.