Windows UI 3 : Controls in WinUI 3 | Basic Inputs — Buttons | WinUI 3 Gallery

VectoArt
3 min readAug 7, 2023

--

A button gives the user a way to trigger an immediate action. Some buttons are specialized for particular tasks, such as navigation, repeated actions, or presenting menus.

Is this the right control?

Use a Button control to let the user initiate an immediate action, such as submitting a form.

Don’t use a Button control when the action is to navigate to another page; instead, use a HyperlinkButton control. For more info about hyperlinks, see Hyperlinks.

Recommendations

  • Make sure the purpose and state of a button are clear to the user.
  • When there are multiple buttons for the same decision (such as in a confirmation dialog), present the commit buttons in this order, where [Do it] and [Don’t do it] are specific responses to the main instruction:
  • Expose only one or two buttons to the user at a time, for example, Accept and Cancel. If you need to expose more actions to the user, consider using checkboxes or radio buttons from which the user can select actions, with a single command button to trigger those actions.
  • For an action that needs to be available across multiple pages within your app, instead of duplicating a button on multiple pages, consider using a bottom app bar.

Button text

A button’s content is usually text. When you design that text, use the following recommendations:

  • Use a concise, specific, self-explanatory text that clearly describes the action that the button performs. Usually button text is a single word that is a verb.
  • Use the default font, unless your brand guidelines tell you to use something different.
  • For shorter text, avoid narrow command buttons by using a minimum button width of 120px.
  • For longer text, avoid wide command buttons by limiting text to a maximum length of 26 characters.
  • If the button’s text content is dynamic (that is, it is localized), consider how the button will be resized and what will happen to controls around it.

Create a button

This example shows a button that responds to a click.

Create the button in XAML.

XAML

<Button Content="Subscribe" Click="SubscribeButton_Click"/>

Or create the button in code.

C#

Button subscribeButton = new Button();
subscribeButton.Content = "Subscribe";
subscribeButton.Click += SubscribeButton_Click;

// Add the button to a parent container in the visual tree.
stackPanel1.Children.Add(subscribeButton);

Handle the Click event.

C#

private async void SubscribeButton_Click(object sender, RoutedEventArgs e)
{
// Call app specific code to subscribe to the service. For example:
ContentDialog subscribeDialog = new ContentDialog
{
Title = "Subscribe to App Service?",
Content = "Listen, watch, and play in high definition for only $9.99/month. Free to try, cancel anytime.",
CloseButtonText = "Not Now",
PrimaryButtonText = "Subscribe",
SecondaryButtonText = "Try it"
};
ContentDialogResult result = await subscribeDialog.ShowAsync();
}

Get the sample code

  • WinUI Gallery: This sample shows all the XAML controls in an interactive format.

--

--

VectoArt

UI/UX Design | WinForms | WPF | Resume Design | UI/UX Design