Click here to Skip to main content
Click here to Skip to main content
Go to top

PopupMenu and Message DailogBox in Windows 8

, 26 Aug 2014
Rate this:
Please Sign up or sign in to vote.
PopupMenu and Message DailogBox in Windows 8

Introduction

I am going to explain how to create a popup menu and message dailogbox in Windows Store apps. When we open any application, there is a menu bar. When we click on any menu item, the popup menu will be shown from which we can select any popup menu item. In this tip, I explain how to create a Popup menu. The message box here is fully user-defined, we can add the commands to the message box and also add an action with it.

  1. Create a new blank app name Popupmenu_N_Msgdialogbox:

  2. Add Button and Popup control in MainPage.xaml:
            <Button Content="Show Popup" 
        Click="ShowPopup" Margin="120,69,0,0" VerticalAlignment="Top"/>
            <Popup  VerticalOffset="10" 
            HorizontalOffset="300" x:Name="StandardPopup" 
    IsLightDismissEnabled="True">
                <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" 
                BorderThickness="2" 
                            Background="{StaticResource ApplicationPageBackgroundThemeBrush}" 
                            Width="212" Height="200">
                    <StackPanel HorizontalAlignment="Center" 
                    VerticalAlignment="Center">
                        <TextBlock Text="Simple Popup" 
                        FontSize="24.667" HorizontalAlignment="Center"/>
                        <Button Content="Close" Click="ShowPopupClose" 
                        HorizontalAlignment="Center"/>
                    </StackPanel>
                </Border>
            </Popup>
  3. And in MainPage.Xaml.cs file, add this code:
            private void ShowPopup(object sender, RoutedEventArgs e)
            {
                if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
            }
    
            private void ShowPopupClose(object sender, RoutedEventArgs e)
            {
                if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
     }
  4. The output of this code is as follows:

  5. Add new Button for message dailogbox:
    <Button Content="MessageDialog Box" Click="MessageDialogBox" HorizontalAlignment="Left" Margin="120,176,0,0" 
                    VerticalAlignment="Top&rdquo; Width="238"/>
  6. Add namespace in mainpage.xaml.cs file:

  7. And add this code in Mainpage.xaml.cs file:
    private async void MessageDialogBox(object sender, RoutedEventArgs e)
            {
                var messagedialog = new MessageDialog("No internet connection has been found.");
                messagedialog.Commands.Add(new UICommand("Try again"));
                messagedialog.Commands.Add(new UICommand("Close"));
                await messagedialog.ShowAsync();
     }
  8. The output of this code is as follows:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shah Ankita
Software Developer
India India
No Biography provided
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 26 Aug 2014
Article Copyright 2014 by Shah Ankita
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid