how do you get the keyboard inputs to work with the RadMenu?

2 Answers 28 Views
Menu
Peter
Top achievements
Rank 1
Iron
Peter asked on 01 Feb 2024, 09:31 PM

Please help. I'm trying to get keyboard inputs to work for a RadMenu. Here are the three different ways I'm trying to get working. Just to be clear, NONE work. And yes, there are valid commands backing these. When I try this with Window.InputBindings I can get it to work, but i would like to have the keyboard declaration as near the menu as possible. This shouldn't be this hard, please help.

<telerik:RadMenu Grid.Row="0" NotifyOnHeaderClick="True" VerticalAlignment="Center" Grid.ColumnSpan="3">
			<telerik:RadMenuItem Header="_File">
				<telerik:RadMenuItem Header="_New" InputGestureText="Ctrl+N" Command="{Binding NewCommand}">
					<telerik:RadMenuItem.InputBindings>
						<KeyBinding Gesture="Ctrl+N" Command="{Binding NewCommand}"/>
					</telerik:RadMenuItem.InputBindings>
				</telerik:RadMenuItem>
				<telerik:RadMenuItem Header="_Save" InputGestureText="Ctrl+S" CommandTarget="{Binding SaveCommand, Mode=OneWay}" />
				<telerik:RadMenuItem Header="_Cancel" InputGestureText="ESC"/>
				<telerik:RadMenuItem Header="_Delete" InputGestureText="Ctrl+D" Command="{Binding DeleteCommand}" />
				<telerik:RadMenuSeparatorItem />
				<telerik:RadMenuItem Header="E_xit" InputGestureText="Alt+F4" Command="{Binding FileExitCommand}" />
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Header="_Help">
				<telerik:RadMenuItem Header="_Support" Command="{Binding NavigateToAvantiSupportWebpageCommand}" CommandParameter="https://avantisystems.com/support-portal/"/>
				<telerik:RadMenuSeparatorItem />
				<telerik:RadMenuItem Header="_About" Command="{Binding HelpAboutCommand}"/>
			</telerik:RadMenuItem>
		</telerik:RadMenu>

2 Answers, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 06 Feb 2024, 09:25 AM

Hello Peter,

I tested the provided code snippet in a sample project on my end and only the NewCommand is executed, as its RadMenuItem instance has a KeyBinding implemented in its InputBindings collection. Setting the InputGestureText property will not associate the input gesture with the menu item. It will only include the text next to it.

Additionally, the key binding will execute the command only when the control instance is focused. This is described in the following StackOverflow article:

wpf - InputBindings work only when focused - Stack Overflow

The above forum thread also provides a solution for this scenario, which I have implemented in the attached test application.

With this being said, may I ask if you could give the sample project a try?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Peter
Top achievements
Rank 1
Iron
answered on 15 Feb 2024, 08:46 PM

Thanks for the reply. Unfortunately I found my own solution. Thankfully. I was disappointed that this wasn't\didn't work as expected. Even more disappointed it's not better documented.

The fix I found was to put <Window.InputBindingson the page. 

Requiring the control to be focused? That certainly takes the Tekerik developer  off the hook for doing what is actually usable. What's usable is being able to use a keyboard from anywhere on the page\form. I'm sorry you don't agree, as you have gone the easy way and are supporting only when the control has focus (as the command on the control doesn't give a compile time error). To be honest, I would MUCH rather a compile time error or simply do NOT support the command. As you can see from the amount of feeedback, people THINK setting the keyboard does more than simply set the text on the menu. I think you should make THAT work instead of skirting the issue, not working and worse, saying it's supported but in a very unintuitive way that is not used by most of the users using  the page\form it's on.

Martin Ivanov
Telerik team
commented on 16 Feb 2024, 03:19 PM | edited

Thank you for sharing your solution.

About the InputBindings, this is WPF-specific behavior that is related to the MS design pattern used for the input gestures. A control must be focused in order to execute its InputBindings. The recommended approach to get shortcuts for the menu items is to define the InputBindings in the appropriate view scope. Usually this is the Window.

Indeed, the RadMenu can implement logic to handle the situation where the key inputs are stolen from an element that is currently focused, but such implementation will cause issues. The menu control should search for the focused element, then it should listen for changes in the focused element, and if someone is handling the keyboard focus event, the menu won't be able to execute the needed logic. Such implementation will also couple the menu with the focused element, which is prompt to memory-related issues.

I have added an item in our backlog to add a documentation resource that shows how to use RadMenu and the WIndow.InputBindings, and also updated your Telerik points as a small gesture of gratitude for bringing this to our attention.


Peter
Top achievements
Rank 1
Iron
commented on 17 Feb 2024, 07:50 PM

Thank you for the comment Martin. I'm not sure what the Telerik points are, but if I have time this weekend I'll go look. More importantly is the reply. Thank you.
Tags
Menu
Asked by
Peter
Top achievements
Rank 1
Iron
Answers by
Stenly
Telerik team
Peter
Top achievements
Rank 1
Iron
Share this question
or