We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Access and Accelerator keys

Two questions regarding access keys:
     How do I get the access key underlined in the menu text? Neither the underscore nor the ampersand work.
     I understand it is necessary to use a keyboard handler to implement the access keys, but how do I expand the top-level menu via code? In other words, if the user presses           ALT + E, the Edit menu should open. Additionally, if the user then presses the T key, the Cut Command should execute.

1 Reply

TB Thirupathi Bala Krishnan Syncfusion Team July 8, 2019 02:56 PM UTC

Hi Chris,

Thanks for contacting Syncfusion support.

Please find our response as below,
 
 
Query 
Response 
How do I get the access key underlined in the menu text? Neither the underscore nor the ampersand work. 
For UWP controls, you can set the mnemonic text by focusing the specific string instead of underlining the string. While clicking the Alt button, the mnemonic text to be highlighted. Please refer the below screenshots for easy understanding. Here ‘F’ and ‘E’ are the mnemonics text. While clicking ‘F’ key, the submenu will be opened. 
 
 
 
For more details, please refer the below msdn link: 
 
You can achieve this requirement by setting the Accesskey for each menu item. After running your application, Pressing the Alt key initializes access key functionality and displays all currently available key combinations in Key Tips. And then invoke the AccessKeyInvoked event handler to handle the click operations of selected menu items.

Please refer the following code sample. 
 
#MainPage.xaml 
 
        <menu:SfMenu  x:Name="menu" HorizontalAlignment="Left" VerticalAlignment="Top"> 
            <menu:SfMenuItem Header="File" AccessKey="F"> 
                <menu:SfMenuItem Header="New" AccessKey="N"/> 
                <menu:SfMenuItem Header="Open" AccessKey="O"/> 
                <menu:SfMenuItemSeparator /> 
                <menu:SfMenuItem Header="Save" AccessKey="S"/> 
                <menu:SfMenuItem Header="Save As" AccessKey="A"/> 
                <menu:SfMenuItemSeparator /> 
                <menu:SfMenuItem Header="Exit" AccessKey="x"/> 
            </menu:SfMenuItem> 
            <menu:SfMenuItem Header="Edit" AccessKey="E"> 
                <menu:SfMenuItem Header="Cut" AccessKey="T" /> 
                <menu:SfMenuItem Header="Copy" AccessKey="C"/>                 
                <menu:SfMenuItem Header="Paste" AccessKey="P"/> 
                <menu:SfMenuItemSeparator /> 
                <menu:SfMenuItem Header="Undo" AccessKey="U"/> 
            </menu:SfMenuItem> 
        </menu:SfMenu> 

#MainPage.xaml.cs
 
 
        public MainPage() 
        { 
            this.InitializeComponent(); 
 
            //Parent menu 
            SfMenuItem edit = (this.menu.Items[1] as SfMenuItem); 
            edit.AccessKeyInvoked += Edit_AccessKeyInvoked; 
 
            //Submenu 
            SfMenuItem cut = edit.Items[0] as SfMenuItem; 
            cut.AccessKeyInvoked += Cut_AccessKeyInvoked; 
        } 
 
        private void Cut_AccessKeyInvoked(UIElement sender, AccessKeyInvokedEventArgs args) 
        { 
            //Write your own code here. 
        } 
 
        private void Edit_AccessKeyInvoked(UIElement sender, AccessKeyInvokedEventArgs args) 
        { 
            //only one submenu should be displayed at a time  
            (this.menu.Items[0] as SfMenuItem).IsSubMenuOpen = false; 
 
            (this.menu.Items[1] as SfMenuItem).IsSubMenuOpen = true; 
        }

 

Please refer the attached videos from the following location:
 
https://www.syncfusion.com/downloads/support/forum/145750/ze/Chris_SfMneu-1198438222

If the above solution does not meet your actual requirement could you please share the detailed description about your requirement, so that it could be helpful to provide the solution at the earliest.
 
 
 I understand it is necessary to use a keyboard handler to implement the access keys, but how do I expand the top-level menu via code?  
You can achieve this requirement by using the IsSubMenuOpen property of menu item. Here you can expand the top level of menu items by using specific index. 

Please refer the following code sample.
 
 
#MainPage.xaml.cs 
 
        public MainPage() 
        { 
            this.InitializeComponent(); 
            this.menu.Loaded += Menu_Loaded; 
        } 
 
        private void Menu_Loaded(object sender, RoutedEventArgs e) 
        { 
            (this.menu.Items[0] as SfMenuItem).IsSubMenuOpen = true;                   
        } 
 
 
 

Sample link: https://www.syncfusion.com/downloads/support/forum/145750/ze/SfMenuDemo-211551402

Please let us know if you need any further assistance.

Regards,
Thirupathi B.
 


Loader.
Live Chat Icon For mobile
Up arrow icon