Dela via


ContentDialog.DefaultButton Property

Definition

Gets or sets a value that indicates which button on the dialog is the default action.

public:
 property ContentDialogButton DefaultButton { ContentDialogButton get(); void set(ContentDialogButton value); };
ContentDialogButton DefaultButton();

void DefaultButton(ContentDialogButton value);
public ContentDialogButton DefaultButton { get; set; }
var contentDialogButton = contentDialog.defaultButton;
contentDialog.defaultButton = contentDialogButton;
Public Property DefaultButton As ContentDialogButton

Property Value

A value of the enumeration. The default is None.

Windows requirements

Device family
Windows 10 Creators Update (introduced in 10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v4.0)

Remarks

You may optionally choose to differentiate one of the three buttons as the default button. Specifying the default button causes the following to happen:

  • The button receives the Accent Button visual treatment
  • The button will respond to the ENTER key automatically
    • When the user presses the ENTER key on the keyboard, the click handler associated with the default button will fire and the ContentDialogResult will return the value associated with the default button
    • If the user has placed focus on a control that handles ENTER, the default button will not respond to ENTER presses
  • The button will receive focus automatically when the dialog is opened unless the dialog’s content contains focusable UI

Version compatibility

The DefaultButton property is not available prior to Windows 10, version 1703. If your app’s 'minimum platform version' setting in Microsoft Visual Studio is less than the 'introduced version' shown in the Requirements block later in this page, you must design and test your app to account for this. For more info, see Version adaptive code.

To avoid exceptions when your app runs on previous versions of Windows 10, do not set this property in XAML or use it without performing a runtime check. This example shows how to use the ApiInformation class to check for the presence of this property before you set it.

<ContentDialog x:Name="contentDialog1" Loaded="ContentDialog_Loaded">
    ...
</ContentDialog>
private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.ContentDialog", "DefaultButton"))
    {
        contentDialog1.DefaultButton = ContentDialogButton.Primary;
    }
}

Applies to