Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

PopupMenu and Message DailogBox in Windows 8

0.00/5 (No votes)
26 Aug 2014 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here