KeyBinding to single Property

Grids for WPF Forum

Posted 6 years ago by Robert
Version: 13.2.0600
Avatar

Hello,

 

we use your PropertyGrid and we have a custom property as a list.

It is possible to add and remove items. The visual style is realized in a datatemplate.

Now we want to add/remove items also per keybinding (insert/delete). We added a keybinding to our datatemplate.

But the keybinding doesn't work if we only focus the property name. We have to focus directly the property value (only possible with the tab key)

Is it possible to add a keybinding to the propertyname? And if yes, how can we do this?

 

Best Regards

Comments (3)

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

Hi Robert,

There are probably several ways to do this.  Each PropertyEditor as well as objects like PropertyGridPropertyItem all have NameTemplate properties.  Basically anywhere that has a ValueTemplate property (which you probably are already setting) should also have a NameTemplate property.  You could just set that in the same fashion as what you do for the ValueTemplate and in the DataTemplate you set, have the keybinding.


Actipro Software Support

Posted 6 years ago by Robert
Avatar

Thank you for your answer. It helped partly. I have created a own DataTemplate for the name of our single property.
 The DataTemplate will be loaded successfully. I tested it with a colored background.

But the keybinding to the command doesn't work

In our DataTemplate for the value the keybinding to the command is working. It's the same viewmodel class.

This is the DataTemplate for the NameTemplate:

<DataTemplate DataType="{x:Type customEditors:EditorForCollectionsDisplayText}" x:Key="EditorForCollectionsDisplayTextNameTemplate">
	<Grid Background="Red" >
		<Grid.InputBindings>
			<KeyBinding Key="Insert" Command="{Binding Value.AddNewItemCommand, RelativeSource={RelativeSource AncestorType={x:Type propertyGrid:IPropertyDataAccessor}}}" />
		</Grid.InputBindings>
		<StackPanel Orientation="Horizontal" >
			<TextBlock Text="{Binding DisplayName, RelativeSource={RelativeSource AncestorType={x:Type propertyGrid:IPropertyDataAccessor}}}" Margin="0 0 15 0"/>
			<TextBlock Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propertyGrid:IPropertyDataAccessor}}}" />
		</StackPanel>
	</Grid>
</DataTemplate>

 

Do you have any ideas?

 

Best Regards

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

Hi Robert,

Hmm... I did some debugging and it looks like when the name cell appears focused, the PropertyGridDataAccessorItem has focus.  Since that is above (in hierarchy) the ContentPresenter that displays the NameTemplate, the key binding won't work.

You might need to add something at the root PropertyGrid level instead that could handle the key and take action when appropriate.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) 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.