PopupMenu and Message DailogBox in Windows 8






4.33/5 (2 votes)
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.
- Create a new blank app name
Popupmenu_N_Msgdialogbox
: - 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>
- 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; } }
- The output of this code is as follows:
- Add new
Button
for message dailogbox:<Button Content="MessageDialog Box" Click="MessageDialogBox" HorizontalAlignment="Left" Margin="120,176,0,0" VerticalAlignment="Top” Width="238"/>
- Add namespace in mainpage.xaml.cs file:
- 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(); }
- The output of this code is as follows: