You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -3,7 +3,7 @@ description: Dialogs display transient UI elements that appear when the user req
3
3
title: Dialog controls
4
4
label: Dialogs
5
5
template: detail.hbs
6
-
ms.date: 02/26/2025
6
+
ms.date: 08/05/2025
7
7
ms.topic: article
8
8
ms.assetid: ad6affd9-a3c0-481f-a237-9a1ecd561be8
9
9
doc-status: Published
@@ -39,20 +39,20 @@ For recommendations on when to use a dialog vs. when to use a flyout (a similar
39
39
- The "do it" action button(s) should appear as the leftmost buttons. The safe, nondestructive action should appear as the rightmost button.
40
40
- You may optionally choose to differentiate one of the three buttons as the dialog's default button. Use the DefaultButton API to differentiate one of the buttons.
41
41
- Don't use dialogs for errors that are contextual to a specific place on the page, such as validation errors (in password fields, for example), use the app's canvas itself to show inline errors.
42
-
- Use the [ContentDialog class](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog) to build your dialog experience. Don't use the deprecated MessageDialog API.
42
+
- Use the [ContentDialog class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog) to build your dialog experience. Don't use the deprecated MessageDialog API.
To create a dialog, you use the [ContentDialog class](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog). You can create a dialog in code or markup. Although its usually easier to define UI elements in XAML, in the case of a simple dialog, it's actually easier to just use code. This example creates a dialog to notify the user that there's no WiFi connection, and then uses the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync) method to display it.
55
+
To create a dialog, you use the [ContentDialog class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog). You can create a dialog in code or markup. Although its usually easier to define UI elements in XAML, in the case of a simple dialog, it can be easier to just use code. This example creates a dialog to notify the user that there's no WiFi connection, and then uses the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog.showasync) method to display it.
When the user clicks a dialog button, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync) method returns a [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialogResult) to let you know which button the user clicks.
71
+
If your content dialog is more complex, it can be easier to create it with XAML. You can either create it in the XAML file for your page, or you can create a subclass of ContentDialog with it's own .xaml and code-behind file. For complete examples of both, see the [ContentDialog] class reference.
72
72
73
-
The dialog in this example asks a question and uses the returned [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialogResult) to determine the user's response.
73
+
There is no item template in Visual Studio to create a new content dialog file, but you can use the Blank Page template and modify the resulting files to create a dialog.
74
+
75
+
**To create a new content dialog with XAML and code-behind**
76
+
77
+
1. In the **Solution Explorer** pane, right-click on the project name and select **Add > New Item...**
78
+
1. In the **Add New Item** dialog, select **WinUI** in the template list on the left-side of the window.
79
+
1. Select the **Blank Page** template.
80
+
1. Name the file. (In this example, the file is named `XamlContentDialog`).
81
+
1. Press **Add**.
82
+
83
+
In the new .xaml file, change the opening and closing Page tags to Content Dialog.
84
+
85
+
```xaml
86
+
<!--
87
+
<Page
88
+
x:Class="ContentDialog_WinUI3.XamlContentDialog"
89
+
...>
90
+
91
+
</Page>
92
+
-->
93
+
94
+
<ContentDialog
95
+
x:Class="ContentDialog_WinUI3.XamlContentDialog"
96
+
...>
97
+
98
+
</ContentDialog>
99
+
```
100
+
101
+
In the .xaml.cs file, make your class inherit from ContentDialog instead of Page.
102
+
103
+
```csharp
104
+
// public sealed partial class XamlContentDialog : Page
> There can only be one ContentDialog open per window at a time. Attempting to open two content dialogs will throw an exception.
123
+
124
+
#### Set the XamlRoot
125
+
126
+
When you show a ContentDialog, you need to manually set the [XamlRoot](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.uielement.xamlroot) of the dialog to the root of the XAML host. To do so, set the ContentDialog's XamlRoot property to the same XamlRoot as an element already in the XAML tree.
127
+
128
+
If the ContentDialog is shown from a [Page](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.page), you can set the ContentDialog's XamlRoot property to the XamlRoot of the Page as shown in the previous example.
129
+
130
+
[Window](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window) doesn't have a XamlRoot property, so if the dialog is shown from a Window, set the dialog's XamlRoot property to that of the Window's root content element, as shown here.
131
+
132
+
```xaml
133
+
<Window
134
+
... >
135
+
<Gridx:Name="rootPanel">
136
+
137
+
</Grid>
138
+
</Window>
139
+
``````
140
+
141
+
```csharp
142
+
private async void DisplayNoWifiDialog()
143
+
{
144
+
ContentDialog noWifiDialog = new ContentDialog
145
+
{
146
+
XamlRoot = rootPanel.XamlRoot,
147
+
Title = "No wifi connection",
148
+
Content = "Check your connection and try again.",
149
+
CloseButtonText = "Ok"
150
+
};
151
+
152
+
ContentDialogResult result = await noWifiDialog.ShowAsync();
153
+
}
154
+
```
155
+
156
+
## Respond to dialog buttons
157
+
158
+
When the user clicks a dialog button, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog.ShowAsync) method returns a [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialogResult) to let you know which button the user clicks.
159
+
160
+
The dialog in this example asks a question and uses the returned [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialogResult) to determine the user's response.
Because dialogs block user interaction, and because buttons are the primary mechanism for users to dismiss the dialog, ensure that your dialog contains at least one "safe" and nondestructive button such as "Close" or "Got it!". **All dialogs should contain at least one safe action button to close the dialog.** This ensures that the user can confidently close the dialog without performing an action.<br>
191
+
Because dialogs block user interaction, and because buttons are the primary mechanism for users to dismiss the dialog, ensure that your dialog contains at least one "safe" and nondestructive button such as "Close" or "Got it!". **All dialogs should contain at least one safe action button to close the dialog.** This ensures that the user can confidently close the dialog without performing an action.
192
+
193
+

105
194
106
195
```csharp
107
196
privateasyncvoidDisplayNoWifiDialog()
@@ -177,16 +266,16 @@ Use the ContentDialog.CloseButton API to create this button. This allows you to
177
266
- The user presses the ESC button on the keyboard.
178
267
- The user presses Gamepad B.
179
268
180
-
When the user clicks a dialog button, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync) method returns a [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialogResult) to let you know which button the user clicks. Pressing on the CloseButton returns ContentDialogResult.None.
269
+
When the user clicks a dialog button, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog.ShowAsync) method returns a [ContentDialogResult](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialogResult) to let you know which button the user clicks. Pressing on the CloseButton returns ContentDialogResult.None.
181
270
182
271
### PrimaryButton and SecondaryButton
183
272
184
273
In addition to the CloseButton, you may optionally present the user with one or two action buttons related to the main instruction.
185
274
Leverage PrimaryButton for the first "do it" action, and SecondaryButton for the second "do it" action. In three-button dialogs, the PrimaryButton generally represents the affirmative "do it" action, while the SecondaryButton generally represents a neutral or secondary "do it" action.
186
275
For example, an app may prompt the user to subscribe to a service. The PrimaryButton as the affirmative "do it" action would host the Subscribe text, while the SecondaryButton as the neutral "do it" action would host the Try it text. The CloseButton would allow the user to cancel without performing either action.
187
276
188
-
When the user clicks on the PrimaryButton, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync) method returns ContentDialogResult.Primary.
189
-
When the user clicks on the SecondaryButton, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync) method returns ContentDialogResult.Secondary.
277
+
When the user clicks on the PrimaryButton, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog.ShowAsync) method returns ContentDialogResult.Primary.
278
+
When the user clicks on the SecondaryButton, the [ShowAsync](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.contentdialog.ShowAsync) method returns ContentDialogResult.Secondary.
190
279
191
280

192
281
@@ -235,13 +324,27 @@ A typical confirmation dialog has two buttons: an affirmation ("OK") button and
235
324
</li>
236
325
</ul>
237
326
238
-
> Some platforms put the affirmation button on the right instead of the left. So why do we recommend putting it on the left? If you assume that the majority of users are right-handed and they hold their phone with that hand, it's actually more comfortable to press the affirmation button when it's on the left, because the button is more likely to be within the user's thumb-arc. Buttons on the right-side of the screen require the user to pull their thumb inward into a less-comfortable position.
> -[Open the WinUI 2 Gallery app and see the ContentDialog in action](winui2gallery:/item/ContentDialog). [!INCLUDE [winui-2-gallery](../../../../includes/winui-2-gallery.md)]
339
+
340
+
We recommend using the latest [WinUI 2](/windows/uwp/get-started/winui2/) to get the most current styles and templates for all controls. WinUI 2.2 or later includes a new template for this control that uses rounded corners. For more info, see [Corner radius](../../style/rounded-corner.md).
341
+
342
+
343
+
### ContentDialog in AppWindow or Xaml Islands
241
344
242
345
> NOTE: This section applies only to apps that target Windows 10, version 1903 or later. AppWindow and XAML Islands are not available in earlier versions. For more info about versioning, see [Version adaptive apps](/windows/uwp/debug-test-perf/version-adaptive-apps).
243
346
244
-
By default, content dialogs display modally relative to the root [ApplicationView](/uwp/api/windows.ui.viewmanagement.applicationview). When you use ContentDialog inside of either an [AppWindow](/uwp/api/windows.ui.windowmanagement.appwindow) or a [XAML Island](../../../desktop/modernize/xaml-islands/xaml-islands.md), you need to manually set the [XamlRoot](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.uielement.xamlroot) on the dialog to the root of the XAML host.
347
+
By default, content dialogs display modally relative to the root [ApplicationView](/uwp/api/windows.ui.viewmanagement.applicationview). When you use ContentDialog inside of either an [AppWindow](/uwp/api/windows.ui.windowmanagement.appwindow) or a [XAML Island](../../../desktop/modernize/xaml-islands/xaml-islands.md), you need to manually set the [XamlRoot](/uwp/api/windows.ui.xaml.uielement.xamlroot) on the dialog to the root of the XAML host.
245
348
246
349
To do so, set the ContentDialog's XamlRoot property to the same XamlRoot as an element already in the AppWindow or XAML Island, as shown here.
> There can only be one ContentDialog open per thread at a time. Attempting to open two ContentDialogs will throw an exception, even if they are attempting to open in separate AppWindows.
> -[Open the WinUI 2 Gallery app and see the ContentDialog in action](winui2gallery:/item/ContentDialog). [!INCLUDE [winui-2-gallery](../../../../includes/winui-2-gallery.md)]
282
-
283
-
We recommend using the latest [WinUI 2](/windows/uwp/get-started/winui2/) to get the most current styles and templates for all controls. WinUI 2.2 or later includes a new template for this control that uses rounded corners. For more info, see [Corner radius](../../style/rounded-corner.md).
373
+
> There can only be one ContentDialog open per thread at a time. Attempting to open two ContentDialogs will throw an exception, even if they are attempting to open in separate instances of AppWindow.
A cryptographic hash function takes an arbitrarily long block of data and returns a fixed-size bit string. Hash functions are typically used when signing data. Because most public key signature operations are computationally intensive, it is typically more efficient to sign (encrypt) a message hash than it is to sign the original message. The following procedure represents a common, albeit simplified, scenario:
126
126
127
-
-Bob and Alice share a secret key and agree on a MAC function to use.
128
-
-Bob creates a message and inputs the message and the secret key into a MAC function to retrieve a MAC value.
129
-
-Bob sends the \[unencrypted\] message and the MAC value to Alice over a network.
130
-
-Alice uses the secret key and the message as input to the MAC function. She compares the generated MAC value to the MAC value sent by Bob. If they are the same, the message was not changed in transit.
127
+
- Alice has a public/private key pair and wants to send a signed message to Bob.
128
+
-Alice creates a message and calculates a hash of the message using a hash function.
129
+
-Alice signs the hash using her private key and sends the \[unencrypted\] message and the signature to Bob over a network.
130
+
-Bob calculates a hash of the received message using the same hash function. He then uses Alice's public key to decrypt the signature and compares it to the calculated hash. If they are the same, the message was not changed in transit and came from Alice.
131
131
132
132
Note that Alice sent an unencrypted message. Only the hash was encrypted. The procedure ensures only that the original message was not altered and, by using Alice's public key, that the message hash was signed by someone with access to Alice's private key, presumably Alice.
0 commit comments