Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
Focus is not lying with main menu


#1. I am using hierarchical data template in XamMenu. Once submenu opens through keyboard navigation. If we are exiting with left arrow button then focus is moving to next element. Ideally Focus need to stay with same parent.

#2. I want to set keyboard navigation as non cyclic. How to achieve this.

No Data
  • 6365
    Offline posted

    Hello viswa,

    1. Presuming that you would like to disable the navigation from one root element to another when you are currently focusing the submenu of the first root element, I can suggest you handle the PreviewKeyDown event of the XamMenu and set the e.Handled property to true if the Left or Right key has been pressed. This will not allow for the default navigation logic to be executed and we will remain within the same root element.

    if (e.Key == Key.Left || e.Key == Key.Right)
        e.Handled = true;

    2. In order to disable the cyclic navigation for the XamMenu (being able to select the first item when pressing the right arrow key on the last and vice versa), you can handle the PreviewKeyDown event as well by adding an explicit check if the first or last item is currently with an open submenu.

    var rootMenuItems = FindVisualChildren<XamMenuItem>(menu).Where(i => i.TemplatedParent == null)

    if ((rootMenuItems.FirstOrDefault().IsSubmenuOpen && e.Key == Key.Left) ||
        (rootMenuItems.LastOrDefault().IsSubmenuOpen && e.Key == Key.Right))
        e.Handled = true;

    I have attached a sample application that demonstrates the approaches from above.

    If you have any questions, please let me know.
No Data