Add custom UIControl to any Editor

Grids for WPF Forum

Posted 2 years ago by Olivier
Version: 22.1.3

Hi Friends,

Some of my properties have there "IsReadOnly" state controled by another "bool" property, and I want to control the "bool" state by pressing a button.

I want this button to be displayed inside the editor, to the right (eg. with a "PadLock" image).

What I wish is to add this button as :

- an adorner to the actual editor UI control, whatever the editor is

- a classic button added to the right of the actual editor UI control, for example within a dockpanel containing both.

To achieve case #1, I need to have somehow access to the underlying UI control created for a given editor, and then add my adorner.

But I don't know how and were to access the actual UI control after its creation and before its display ...

To achieve case #2, I've created a custom Editor whos ValueTemplate looks like :

		Style='{StaticResource {x:Static themes:SharedResourceKeys.EmbeddedButtonBaseOverrideStyleKey}}'
		ContentTemplate='{Binding " + $"{nameof(MyPropertyModel.LockedOriginalEditor)}.{nameof(PropertyEditor.ValueTemplate)}" + @"}'

MyPropertyModel.LockedOriginalEditor is the original Editor, for example a DoublePropertyEditor.

Display is OK, but when ProperyGrid tries to bind to the underlying editor, it expects a DoublePropertyEditor but finds my custom "high level" editor instead, and many bindings fail.

Would appreciate some help on that one ;-)

[Modified 2 years ago]

Comments (2)

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

Hi Olivier,

Instead of that, you might want to try overridding our PropertyGrid.ValueContainerStyle property.  I see you have WPF Studio so please go to your account and download the default styles/templates for the product from there, at the same Actions menu where you got your license.  Then look in the PropertyGrid's Generic.xaml file for "ValueContainerStyle" to see our default.

What you could do is clone that and inject another ToggleButton there for your lock.  Bind its IsChecked property to the property model's IsValueReadOnly property, which indirectly will then resolve to update the property model's IsReadOnly property value.  I think that will do the trick and should work for everything.

Actipro Software Support

Posted 2 years ago by Olivier

Works great, thank you ;-)

The latest build of this product (v24.1.2) 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.