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.
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.
XAML Code
- <Page
- x:Class="Message_Dialog_Demo.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:Message_Dialog_Demo"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Button Content="Show Message Dialog" HorizontalAlignment="Left" Margin="308,197,0,0" VerticalAlignment="Top" Height="60" Width="138" Click="Button_Click"/>
- </Grid>
- </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:
Change the button click event to async as shown in the following.
Now write the following code in the button click event.
C# Code
- private async void Button_Click(object sender, RoutedEventArgs e)
- {
- MessageDialog message = new MessageDialog("Hi Message dialog");
- await message.ShowAsync();
- }
The full code page looks like the following screen.
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.