UWP MessageDialog
The MessageDialog class represents a dialog for showing messages to the
UWP app user. The MessageDialog class has two constrictors, so the .net
developers can create a MessageDialog instance with these two constructors.
In the following UWP app development tutorial code, we created a message dialog instance with a message and a title. To do this we used the MessageDialog class’s MessageDialog(String, String) constructor.
The MessageDialog(string content) constructor initializes a new instance of the MessageDialog class to display an untitled message dialog. Here the content parameter value is a String which is the message displayed to the UWP app user.
The MessageDialog(string content, string title) constructor initializes a new instance of the MessageDialog class to display a message dialog with a title. The content parameter is the message displayed to the user. And the title parameter is the title that the developers want to display on the dialog.
The .net UWP developers should use the message dialog to display a critical message or ask questions that must block the user’s flow.
The MessageDialog ShowAsync() method is used to begin an asynchronous operation showing a dialog. So finally, we can initialize a MessageDialog instance by using one of its constructors and display it on the app user interface by calling the ShowAsync() method.
In the following UWP app development tutorial code, we created a message dialog instance with a message and a title. To do this we used the MessageDialog class’s MessageDialog(String, String) constructor.
The MessageDialog(string content) constructor initializes a new instance of the MessageDialog class to display an untitled message dialog. Here the content parameter value is a String which is the message displayed to the UWP app user.
The MessageDialog(string content, string title) constructor initializes a new instance of the MessageDialog class to display a message dialog with a title. The content parameter is the message displayed to the user. And the title parameter is the title that the developers want to display on the dialog.
The .net UWP developers should use the message dialog to display a critical message or ask questions that must block the user’s flow.
The MessageDialog ShowAsync() method is used to begin an asynchronous operation showing a dialog. So finally, we can initialize a MessageDialog instance by using one of its constructors and display it on the app user interface by calling the ShowAsync() method.
MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel
x:Name="stack_panel1"
Margin="100"
Orientation="Vertical"
>
<Button
x:Name="button1"
Content="Show Message Doalog"
Click="Button1_Click"
/>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
// Initialize a new text for message dialog
string message = "This is a simple message dialog.";
// Initialize a new MessageDialog instance
MessageDialog messageDialog = new MessageDialog(message, "Dialog Title");
// Display the message dialog
messageDialog.ShowAsync();
}
}
}
