How to use MessageDialog in Windows Store App

How to use a MessageDialog Class
  • 3728
Add reference to using Windows.UI.Popups;

OpenFileButtonClick is a button click event handler where you want to display a message box. 

private async void OpenFileButtonClick(object sender, RoutedEventArgs e)
{
    // Create a MessageDialog
    var messageDialog = new MessageDialog("Hello Windows Store App.");
    var messageDialog2 = new MessageDialog("Hello Windows Store App.", "Hello Windows");
messageDialog.Content = "Hello Windows Store App.";
string message = messageDialog.Content;
            
messageDialog.Title = "Hello Windows";
string title = messageDialog.Title;
     
    // Add commands and set their callbacks. You can create a single callback
    // Or create a separate callback for different commands
    messageDialog.Commands.Add(new UICommand(
        "OK", new UICommandInvokedHandler(this.CommandInvokedHandler)));
    messageDialog.Commands.Add(new UICommand(
        "Close", new UICommandInvokedHandler(this.CommandInvokedHandler)));

    // Set CommandIndex. 0 means default. 
    messageDialog.DefaultCommandIndex = 0;
    messageDialog.CancelCommandIndex = 1;

          
    // Show MessageDialog
    await messageDialog.ShowAsync();
}

private void CommandInvokedHandler(IUICommand command)
{
    // Do something here on the command handler          
}

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.