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

ShortCut Keys in HierarchicalDataTemplate

3 Answers 143 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Manishkumar
Top achievements
Rank 1
Manishkumar asked on 17 May 2011, 08:39 AM
Hi,
I was stuck at a point where I need to assign a shortcut key which is stored in the database respective to a menu.
When I fetch the data the for the menu, I fetch all the details related to it, in a hierarchical manner and bind it to RadMenu DataSource.
Now my requirement is to assign the shortcut key to each RadMenuItem in the RadMenu, for this I thought of creating a CustomCommand using RoutedCommand, CommandBinding and KeyGesture. With this will create a MenuRoutedCommand and thus create a Command that will be assigned to each RadMenuItems command property.

But when i found the RadMenu items in loaded event, those items are not the RadMenuItem but the collection of Hierarchical object used to create the item. So, not able to assign Command as I was unable to get the RadMenuItem.

Please let me know how to assign Command in HierarchicalData source.

Or If there is anyother approach to assign shortcut keys dynamically to the RadMenuItem.

Please reply to it as soon as possible.

Thanks.
 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 17 May 2011, 12:24 PM
Hello Manishkumar,

You have two options:
  1. Use Binding and bind Command property to the ICommand for your data object:
<Style TargetType="telerik:RadMenuItem">
   <Setter Property="Command" Value="{Binding Command}" />
</Style>

   2.   Second option is to use code behind and get the containers and set its Command property like this:
var menuItem = menu.ItemContainerGenerator.ContainerFromIndex(0) as RadMenuItem;
if(menuItem != null)
{
   menuItem.Command = ... // your command here.
}

I hope that this will help you.

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
Manishkumar
Top achievements
Rank 1
answered on 18 May 2011, 07:58 AM
Hi Hristo,
Thanks for your reply.
I tried to implement the above code, but facing lot many problems.
Could you please help me by providing a working example for implementing the shortcut keys in radMenu.
Just take an example that there are two MenuItem inside a menu

File
    Save Ctrl+S
    Close Ctrl+Z

When I press Ctrl+S then it should perform save, same as when Ctrl+Z close the application, without being focus on the RadMenu Item.
These are not static, comes from the database.

Thanks.
0
Hristo
Telerik team
answered on 19 May 2011, 07:56 AM
Hello Manishkumar,

ShortcutCut keys does not support CTRL key, only ALT. This comes from the platform and as far as I know cannot be changed. Also RadMenuItem that is not visible cannot raise a command.

I have attached sample project demonstrating how you can bind RadMenuItem to commands that come from database (although I'm not sure how can this commands be serialized into database).

In order to support you scenario with CTRL key I have added two KeyBindings at Window level. This way you could trigger SaveCommand using CTRL+S, or ALT+F (to open File menuitem) and then ALT+S to trigger save command on RadMenuItem.

I hope that this will help you.

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
Manishkumar
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Manishkumar
Top achievements
Rank 1
Share this question
or