Message Dialog For Windows 10

MessageDialog class represents a dialog. The dialog has a command bar that can support up to three commands. If you don't specify any commands, then a default command is added to close the dialog.

The dialog dims the screen behind it and blocks touch events from passing to the app's canvas until the user responds.

Message dialog should be used sparingly, and only for critical messages or simple questions that must block the user's flow.

Step 1: Open a blank app and add a Button and a TextBlock either from the toolbox or by copying the following XAML code into your grid.
  1. <StackPanel>  
  2. <TextBlock Text="Message Dialog" Margin="10" FontSize="20"></TextBlock>  
  3. <StackPanel Margin="10,20,0,0">  
  4. <Button Name="messageDialog" Height="40" Width="140" Content="Launch" Click="messageDialog_Click"></Button>  
  5. <TextBlock Name="command_Chosen" Margin="10,20,0,0" Height="50" FontSize="20"></TextBlock>  
  6. </StackPanel>  
  7. </StackPanel>  
 

Step 2:
Add the following namespaces to your project which is needed in further C# code.
  1. using Windows.UI.Popups;  


Step 3: Copy and paste the following code to the cs page which will be called on button click event and Message Dialog will be opened
  1. private async void messageDialog_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.     var messageDialog = new MessageDialog("New updates have been found for this program. Would you like to install the new updates?", "Updates available");  
  4.     messageDialog.Commands.Add(new UICommand("Don't install", null, 0));  
  5.     messageDialog.Commands.Add(new UICommand("Install updates", null, 1));  
  6.     messageDialog.DefaultCommandIndex = 1;  
  7.     var commandChosen = await messageDialog.ShowAsync();  
  8.     command_Chosen.Text = "The '" + commandChosen.Label + "' (" + commandChosen.Id + ") command has been selected.";            
  9. }  

Step 4: Run your application and test yourself.

Up Next
    Ebook Download
    View all
    Learn
    View all