News
  • Favorite
  • Facebook
  • Twitter
  • LinkedIn

Microsoft Press Pearson Education (InformIT)
Skip Navigation Links
Pearson Education (InformIT)
How to: Display a message box in Windows 8 Store Apps using C#

Sometimes you want to display a message to the user of your application about error or information. But there is no MessageBox class in Windows 8 Store App. In this article we will show you how to display a message box to your application users.

Create a Blank Windows Store App

1.      Open Visual Studio 2012 Express for Windows 8.

2.      Click on New Project. The New Project Dialog box appears.

3.      From the left pane select C# and then Windows Store Templates.

4.      From the right pane select Blank App (XAML).

5.      Type your project name and then click Ok. We set the project name to MessageBoxApp.

New Project Dialog

Create the UI and adding Xaml Code

1.      Open the MainPage.xaml file by double clicking the MainPage.xaml file from the Solution Explorer.

2.      Select the XAML view and find the Grid Control in the MainPage.xaml.

3.      Add the following code to the Grid in the MainPage.xaml.

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">

    <Grid.RowDefinitions>

        <RowDefinition Height="1*"/>

        <RowDefinition Height="1*"/>

        <RowDefinition Height="1*"/>

    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>

        <ColumnDefinition Width="1*"/>

        <ColumnDefinition Width="1*"/>

        <ColumnDefinition Width="1*"/>

    </Grid.ColumnDefinitions>

    <Button Name="DisplayMessageButton" Content="Display Message" HorizontalAlignment="Left" Grid.Row="1"

            Grid.Column="1" Margin="10" VerticalAlignment="Top" Width="228" Height="80" />

</Grid>

 

a.      The above code creates a Grid with 3 equal height rows and 3 equal width columns.

b.     Add a Button control and name it DisplayMessageButton, sets its Content property to Display Message.

c.      It places the button in second row using Grid.Row attached property and second column using Grid.Column attached property.

d.     Sets the DisplayMessageButton width to 228 Device Independent Pixels (DIPs) and height to 80 DIPs.

e.     Sets the DisplayMessageButton margin to 10 DIPs.

 

New Project Dialog

Adding C# Code and displaying Message Box

4.      Double click the DisplayMessageButton to create the Event Handler for the Click Event.

5.      Mark the DisplayMessageButton_Click method as asynchronous using the async keyword.

6.      Add the following code to the click event handler.

 

private async void DisplayMessageButton_Click(object sender, RoutedEventArgs e)

{

    MessageDialog messageDialog = new MessageDialog("Welcome to Windows 8 Store Apps", "Windows 8");

    await messageDialog.ShowAsync();

}


a.      The above code simply creates an object of the MessageDialog class. This class represents a dialog. The dialog has a command bar that can support up to three commands. If you don't specify any commands, then a default command is added to close the dialog.

b.     We set the content of the MessageDialog to "Welcome to Windows 8 Store Apps".

c.      We set the title of the MessageDialog to "Windows 8".

d.     Then we call the ShowAsync asynchronous method and we should mark this call with the await keyword you can read more about async and await keywords in Asynchronous Programming with Async and Await

7.      Build your application and run it in the Simulator. You will find something similar to the following image

New Project Dialog

8.      Click on the DisplayMessage Button. This will show the Message Dialog with the title and content we set.

New Project Dialog

Now you have a Windows Store Application that displays a message box to your application users. Message dialogs should be used sparingly, and only for critical messages or simple questions that must block the user's flow.

(109) Comments

Blog Message http://biz.malaysiantalks.com/news/cookie-s-kids-children-school-uniform-fashion-trends-for-2019/144388/

Im thankful for the article.Really looking forward to read more. Really Great.


Blog Message http://olin6727aa.recmydream.com/create-or-fine-tune-a-retirement-income-pre-retirement-income-to-continue-your-current-quality-of-life

iаЂа›?Splendid post writing. I concur. Visit my blog for a free trial now! Enjoy secret enlargement tips. Get big and rich. Did I mention free trial? Visit now.


Blog Message http://digg.formation-referencement-nantes.fr/story.php?title=vong-bi-skf-2#discuss

Pretty! This was an incredibly wonderful article. Thank you for providing these details.


Blog Message http://knight-soldiers.com/2019/03/14/bagaimana-cara-mendaftar-akun-pb-garena-dan-juga-cara-verifikasinya/

Im obliged for the article.Really thank you! Cool.


Blog Message http://findcannon67.wikidot.com/blog:1029

I usually have a hard time grasping informational articles, but yours is clear. I appreciate how you ave given readers like me easy to read info.


Blog Message http://randal3588zp.thedeels.com/i-think-this-is-a-wonderfully-quirky-design-that-features-fabulous-twist-on-a-special-part-of-your-child-or-teenagers-life-making-sure-that-the-memories-of-their-happiest-years-live-on-forever-custom-

to be using? I am having some small security problems with


Blog Message http://sevgidolu.biz/user/conoReozy745/

I'а†ve recently started a web site, the info you provide on this website has helped me greatly. Thank you for all of your time & work.


Blog Message http://court.uv.gov.mn/user/BoalaEraw184/

Very good article post.Really thank you! Keep writing.


Blog Message http://aljaberqatar.com/__media__/js/netsoltrademark.php?d=www.blucobalto.it%2Findex.php%3Foption%3Dcom_k2%26view%3Ditemlist%26task%3Duser%26id%3D1274684

Online Shop To Buy Cheap NFL NIKE Jerseys


Blog Message http://openmoscow.ru/go.php?url=https://www.telesputnik.ru%2Fwiki%2Findex.php%3Ftitle%3D%D0%A3%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8%D0%BA%3ARependapi%26action%3Dsubmit/

Spot on with this write-up, I absolutely think this amazing site needs much more attention. I all probably be back again to see more, thanks for the information!


Blog Message https://ruleshelf1.planeteblog.net/2019/02/24/personal-computer-games-free-download-for-windows-7/8/10/xp/

So cool The information mentioned in the article are some of the best available


Blog Message http://alec7949lb.wickforce.com/according-to-kiyosaki-the-main-reason-people-struggle-financially-is-already-doing-what-you-plan-to-do

Really appreciate you sharing this post.Much thanks again. Much obliged.


Blog Message https://www.entclassblog.com/

Of course, what a great blog and educative posts, I will bookmark your site.Have an awsome day!


Blog Message https://write.as/n6agym3vj4hdw

Thanks so much for the blog.Much thanks again. Fantastic.


Blog Message http://www.jnshh.com/__media__/js/netsoltrademark.php?d=vezemsp.ru%2Findex.php%3Foption%3Dcom_k2%26view%3Ditemlist%26task%3Duser%26id%3D799579

Thanks again for the blog article. Much obliged.

First Previous 1 2 3 4 5 6 7 8 Next Last 
Rating
Name
Email
Comment