UWA Message Dialog

To show a Message Dialog in Windows 10 (Universal Windows App) you have to use Windows.UI.Popups

using Windows.UI.Popups;

After you can create a basic dialog like this:

// Create the message dialog and set its content; it will get a default "Close" button since there aren't any other buttons being added
var messageDialog = new MessageDialog("You've exceeded your trial period.");

// Show the message dialog and wait
var res = messageDialog.ShowAsync();

If you want to customize your button, you can use another way:

/// 
/// Click handler for the 'CancelCommandButton' button.
/// Demonstrates setting the command to be invoked when the 'escape' key is pressed.
/// Also demonstrates retrieval of the label of the chosen command and setting a callback to a function.
/// A message will be displayed indicating which command was invoked.
/// In this scenario, 'Try again' is selected as the default choice, and the 'escape' key will invoke the command named 'Close'
/// 
private async void CancelCommandButton_Click()
{
	// Create the message dialog and set its content
        var messageDialog = new MessageDialog("No internet connection has been found.");

	// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
	messageDialog.Commands.Add(new UICommand("Try again", new UICommandInvokedHandler(this.CommandInvokedHandler)));
	messageDialog.Commands.Add(new UICommand("Close", new UICommandInvokedHandler(this.CommandInvokedHandler)));

	// Set the command that will be invoked by default
	messageDialog.DefaultCommandIndex = 0;

        // Set the command to be invoked when escape is pressed
        messageDialog.CancelCommandIndex = 1;

        // Show the message dialog
        await messageDialog.ShowAsync();
}

#region Commands
/// 
/// Callback function for the invocation of the dialog commands.
/// 
/// The command that was invoked.
private void CommandInvokedHandler(IUICommand command)
{
	// Display message showing the label of the command that was invoked
        Debug.WriteLine("The '" + command.Label + "' command has been selected.");
}
#endregion

Advertsing

125X125_06

TagCloud

MonthList

CommentList