ShortCut Keys in HierarchicalDataTemplate

4 posts, 0 answers
  1. Manishkumar
    Manishkumar avatar
    240 posts
    Member since:
    Feb 2009

    Posted 17 May 2011 Link to this post

    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.
     
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 17 May 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Manishkumar
    Manishkumar avatar
    240 posts
    Member since:
    Feb 2009

    Posted 18 May 2011 Link to this post

    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.
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 19 May 2011 Link to this post

    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
Back to Top