Handle button click of button inside a PropertyGridPropertyItem DataTemplate

Grids for WPF Forum

Posted 5 years ago by Miles Merckel
Version: 14.2.0610
Avatar

Hi

 

I'm trying to create a textbox and associated button inside a PropertyGridPropertyItem. I have managed to do this using a DataTemplate binded to the items ValueTemplate, similar to the "Custom Factory (Dictionary)" example.

 

The problem is trying to create or handle the click event from the button. Looking at the Custom Factory example a Command is used but there is some serious layers of complexity used which loses me. Is there a simpler way or do you have an example without the same level of binding?

 

Additionally I'm trying to determine when PropertyGridPropertyItem text entry changes.TextInput, PreviewTextInput, KeyDown, KeyUp events don't seem to fire. PropertyChanged fires when the focus is lost but fires 4 times. I presume there's something I've not setup?

Is it possible to detect when data is keyed in to PropertyGridPropertyItem without having to loose the focus, similar to textbox PreviewTextInput? The PreviewTextInput event of the PropertyGrid containing the various PropertyGridPropertyItem fires when text is entered but I don't know which item changed.

 

Many Thanks

Miles

[Modified 5 years ago]

Comments (4)

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

Hi Miles,

When working with DataTemplates in general in WPF, you can't attach event handlers to code in them.  That's why we use commands there.  There isn't really a simpler way to use commands than in the examples.

Another thing you could do if you didn't want to use commands is to make your own custom control that wraps the button (like a UserControl or a templated Control) and handle the button click event in that custom control's logic.  Then embed the custom control in the DataTemplate. 

That concept might also help with how you are trying track key input, if your TextBox is also in the custom control.  Since then you could attach to its TextChanged event or other key events and take appropriate action without waiting for LostFocus.  The TextBox normally doesn't push the value through to the Binding of the data accessor until LostFocus since TextBox controls by default have an UpdateSourceTrigger of LostFocus on their Bindings instead of PropertyChanged.


Actipro Software Support

Posted 4 years ago by Miles Merckel
Avatar

Hi

Thanks for the reply. I went down the path of implementing the Command basing it on the “Custom Factory (Dictionary)”. Had/having issues with this, the button was there but disabled, ended up moving the Command implementation to the MainWindow code which seemed to fix it but...

The PropertyGrid is in a ToolWindow which when floated disables the button, re-docking enables the button. The “Custom Factory” example is not in a docking window so can’t compare, any clues as to why this is getting disabled when floated.

Using the sample application is useful but I wish there were additional stripped down smaller examples or tutorials with minimal binding. I realise a large part of these libraries is based on binding but sometimes the level of abstraction muddies the whole point of demonstrating a feature or function.

 

Many Thanks

Miles

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

Hi Miles,

The way routed commands work, you can handle them in any ancestor control of the control they are assigned to and that should pick them up.  I would try adding your CommandBinding directly to the PropertyGrid.CommandBindings collection and see if that works.  That will keep it contained within the PropertyGrid itself and should work in a docking window.


Actipro Software Support

Posted 4 years ago by Miles Merckel
Avatar

Hi

 

I've made a small project to determine my issue for which it still disables the button when the toolwindow is floating. I've had to work on other priority stuff but when I get a chance will investigate this further.

 

Many Thanks

Miles

The latest build of this product (v2019.1 build 0681) was released 19 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.