UWP C# XAML how to add shortcuts for accessing standard buttons

CyberSteve 156 Reputation points

In the past you could just put an & sign before the character which indicated the uuser would be able to press Alt + whatever the character was following the &. For example, "C&lose". This doesn't seem to work in UWP. So how do you quickly create a keyboard shortcut for buttons and other elements?

Also, how do you designate a button to be the default wen there are more than one? This should be so obvious, but I'm discovering lots of things in UWP/Xaml that aren't so obvious.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,516 Reputation points

    I forget if it ever was an ampersand, you could be right. For WPF it is an underscore. For UWP use AccessKey,
    as in AccessKey="A".

    For UWP there is not an easy way to make a button a default button.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AryaDing-MSFT 2,841 Reputation points


    Welcome to Microsoft Q&A!

    Uwp provides Access keys for users to quickly navigate and interact with an app’s visible UI through a keyboard.

    As follows:

        <Button  AccessKey="S" Content="Save"/>  
        <Button  AccessKey="M" Content="Modify"/>  
        <Button  AccessKey="A" Content="Add"/>  
        <Button AccessKey="R" Content="Remove"/>  
        <Button AccessKey="L" Content="Load"/>  
        <Button AccessKey="L1" Content="Load"/>      
        <Button AccessKey="R" Content="Refresh"/>  

    When you click Alt key, these access keys will appear, then you input the corresponding access key, the button click event will be triggered.
    You need to notice the access key collisions, if you define two same access key for two buttons, as the above shown, when you click Alt then click R, only the Remove button click event will be triggered, the Refersh button event will be ignored. This issue also happens to L and L1 button. Therefore, please use single and non-repeating character to define AccessKey as much as possible.

    Note that before Windows 10 Creators Update and older, some controls didn’t support built-in access key scopes. But there is another way to implement it. More info could be found here.

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.