In this article we are going to see how to show a message dialog in your Windows 10 apps on the Desktop and Mobile devices using C# and XAML. The MessageDialog class is available in Windows 10. We now have a Universal Windows Platform (UWP).
Create new Windows 10 UWP app and name it as you wish. Now go to Mainpage.Xaml and paste the following XAML code to create a button for showing message dialog.
- <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
- <Button x:Name="Showbutton" Click="Showbutton_Click" Content="Show Message Dialog"/>
- </StackPanel>

Now go to code behind page and write the following code on button click event.
- private async void Showbutton_Click(object sender, RoutedEventArgs e)
- {
- MessageDialog showDialog = new MessageDialog("Hi Welcome to Windows 10");
- showDialog.Commands.Add(new UICommand("Yes")
- {
- Id = 0
- });
- showDialog.Commands.Add(new UICommand("No")
- {
- Id = 1
- });
- showDialog.DefaultCommandIndex = 0;
- showDialog.CancelCommandIndex = 1;
- var result = await showDialog.ShowAsync();
- if ((int) result.Id == 0)
- {
- //do your task
- }
- else
- {
- //skip your task
- }
- }
Use ShowAsync() method to show the dialog and check the result containing command id and perform the yes or no task.
Now run your app with Local Machine, Mobile and Simulator to see the output as in the following image.
Local Machine

Mobile

Simulator

Simulator and Mobile

Source code.


Kumaresh RajalingamPosted Feb 19, 2016, 2:56 PM EST
good one
Kumaresh RajalingamPosted Feb 19, 2016, 2:56 PM EST
Nice explanation
Sr KarthigaPosted Feb 16, 2016, 4:57 PM EST
good explanation
Sr KarthigaPosted Feb 16, 2016, 4:57 PM EST
Nice one
Harshad PansuriyaPosted Oct 29, 2015, 9:49 PM EDT
Nice one
Mohammed IbrahimPosted Oct 28, 2015, 5:25 AM EDT
nice
Nilesh JadavPosted Oct 28, 2015, 4:30 AM EDT
Good Share
Sibeesh VenuTOP 100Posted Oct 28, 2015, 3:26 AM EDT
Nice Share
Mukesh KumarPosted Oct 28, 2015, 1:12 AM EDT
Nice One
Pramod KumarPosted Oct 27, 2015, 11:31 PM EDT
Good Job