This is a migrated thread and some comments may be shown as answers.

Application keyboard shortcuts for RadMenuItems

5 Answers 339 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 11 May 2011, 01:39 PM
Hey everyone,

I've been working hard for a solution for this but to no avail up to this point.  We are working in a WPF - XBAP configuration to port a legacy PowerBuilder app and are finding ourselves mostly at home using the Telerik WPF Controls.  While our issue may not be directly related to the controls in particular, it is a factor of using them for specific purposes.  We are using an overall RadMenu for navigation and obviously input accelerators (Alt+M,S, etc.) generally conflict with the browser.  However, keyboard shortcuts themselves, something like a Ctrl+Shift+M, do not conflict.  I'm looking for a configuration that allows the shortcuts to be mapped to RadMenuItem clicks application wide, so that they are focus independent and always bubble to the Menu.  So far, I've been at a loss to narrow down my search to exactly what I need and, being new to WPF, it's already been a learning curve ahead.

What approach would you recommend for achieving this?  Would doing the same setup work differently/better with a standalone WPF app or a Silverlight app such that it is truly the XBAP format that is hurting my implementation of this so far?

Thanks a ton,
Adam.g

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 13 May 2011, 07:42 AM
Hi Adam,

I'm not sure that I understand your use case correctly so please correct me if I'm wrong. You want to have different elements that trigger the same action and the handling of this action to be centralized - on a single location, right?

If that is correct then this can be achieved using KeyBinding and Commands. For example on a RadMenuItem you add RoutedCommand for Open action (for example). You can also set KeyBinding that will trigger the same command for Ctrl+Shift+O combination.
Then you can set CommandBinding at the Window that will handle execution of your Open command no matter which item triggers it (e.g. RadMenuItem or the KeyBinding).

This is in general the approach that is recommended. You can read more about Commands and KeyBinding here:
http://msdn.microsoft.com/en-us/library/ms752308.aspx

Let us know if you need more information.

Greetings,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Adam
Top achievements
Rank 1
answered on 16 May 2011, 03:08 PM
I will provide a bit more detail.

At its root, we have the xaml App, that startup uri being a "master page" with a RadMenu being its only content.  These menu items need to be the target for any of the defined keyboard shortcuts.  I explored the KeyBindings and CommandBindings a bit before posting, and when focus was on the Menu, they fired correctly, but when the Page itself was in logical focus, I don't believe the commands would get routed up correctly to the Menu.  I suppose that step one could be to have the Master Page catch the commands and then handle them outside of the Menu, but I wanted to check beforehand on the recommended approach.

The other side of this equation is that any of the content "navigated" to in the RadMenu will be hosted in RadWindows, so the Key commands should also be handled when focus is in any of the windows.  This is probably a simple problem to solve, but hopefully this will help understanding.  Basically, from any logical focus in the app, we need the shortcuts to "bubble up" to the Root Browser hosting the master page and Menu.  Does this help?

Adam.g
0
Hristo
Telerik team
answered on 17 May 2011, 10:09 AM
Hi Adam,

You should handle the commands on the master page (as you suggested) instead of RadMenu.
RadMenuItems will fire the Command and if it is RoutedCommand it will bubble and get to the master page.
The same is true for KeyBindings - e.g. if you associate KeyBinding with some Command this command will be routed when key combination is hit.
As for RadWindows - when hosted in browser application we show them in Adorner layer which means that routed command will still bubble up to the master page.

I hope that this will help.

Greetings,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Adam
Top achievements
Rank 1
answered on 17 May 2011, 08:42 PM
I've added the commands to the master page and those are successfully called from the menu, but it doesn't appear possible to even focus the master page itself.  Does that sound like a limitation that you are aware of?  The command also does not appear to bubble up from windows either.  Again, like before, when focus is in the RadMenu itself, the commands appear to be getting to the master page.

Are there any good online examples that you know of for handling something more specific along these lines?
0
Hristo
Telerik team
answered on 18 May 2011, 07:32 AM
Hi Adam,

I forgot to mention that if RadMenuItem does not have CommandTarget then the routed command is executed from the focused element. So this may cause the problem in your case.
Try specifying CommandTarget to be the same RadMenuItem (using Binding Self).

If this does not help please send us your project. This way I will be able to help you faster.

Regards,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Menu
Asked by
Adam
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Adam
Top achievements
Rank 1
Share this question
or