Add custom UIControl to any Editor

Grids for WPF Forum

Posted 1 month ago by Olivier
Version: 22.1.3
Avatar

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 :

<DockPanel
	LastChildFill='True'
>
	<Button
		DockPanel.Dock='Right'
		Margin='1'
		Focusable='False'
		Style='{StaticResource {x:Static themes:SharedResourceKeys.EmbeddedButtonBaseOverrideStyleKey}}'
	/>
	<ContentControl
		Content='{Binding}'
		ContentTemplate='{Binding " + $"{nameof(MyPropertyModel.LockedOriginalEditor)}.{nameof(PropertyEditor.ValueTemplate)}" + @"}'
	/>
</DockPanel>

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 1 month ago]

Comments (2)

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

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 1 month ago by Olivier
Avatar

Works great, thank you ;-)

The latest build of this product (v22.1.4) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.