How to Show Message Dialog in Windows Store 8.1 App

In this article we will see how to show message dialog in a Windows Store app.

Create a new Windows Store Blank Project with a proper name. Here I used “Message Dialog Demo” as shown in the following screen.

message dialog demo

Now drag and drop one button from the toolbox to show the message dialog change the button content to Show Message Dialog. After completion the design part looks as in the following screen.

drag and drop button

XAML Code

  1. <Page  
  2.     x:Class="Message_Dialog_Demo.MainPage"  
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  5.     xmlns:local="using:Message_Dialog_Demo"  
  6.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
  7.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
  8.     mc:Ignorable="d">  
  9.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  10.         <Button Content="Show Message Dialog" HorizontalAlignment="Left" Margin="308,197,0,0" VerticalAlignment="Top" Height="60" Width="138" Click="Button_Click"/>  
  11.     </Grid>  
  12. </Page>  
Now go to the coding part. Simply double-click the “Show Message Dialog” button and it will automatically create the event handler and it goes to the coding page.

Now write the following code to show the message dialog as “Hi Message dialog”.

To show the message dialog include the namespace given below:
  1. Using Windows.UI.Popups;  
Change the button click event to async as shown in the following.

add async

Now write the following code in the button click event.

C# Code
  1. private async void Button_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.       MessageDialog message = new MessageDialog("Hi Message dialog");  
  4.       await message.ShowAsync();  
  5. }  
The full code page looks like the following screen.

message dailog box code

Run the application by pressing the F5 Key directly in your keyboard. Press the Show Message Dialog button and you will see the output as shown below.

show message

 


Similar Articles