How to add a menu to an app bar (Windows Store apps using C#/VB/C++ and XAML)
When you add commands to an app bar, consider whether your command sets would work better in a command menu. Menus let you present more options in less space and include interactive controls. In this example, the Sort menu pops up a simple list that makes choosing options easy.
Roadmap: How does this topic relate to others? See:
What you need to know
Technologies
Prerequisites
Instructions
Step 1: Add an app bar to the app
- Add an app bar to your app. For more info, see Quickstart: Adding app bars.
Here, we add a bottom app bar with a button to show the sort menu.
<Page.BottomAppBar> <AppBar x:Name="bottomAppBar" IsSticky="True"> <Grid> <StackPanel x:Name="rightPanel" Orientation="Horizontal" HorizontalAlignment="Right"> <Button Style="{StaticResource AppBarButtonStyle}" Content="" AutomationProperties.Name="Sort" AutomationProperties.AutomationId="SortButton" Click="SortMenuButton_Click" /> </StackPanel> </Grid> </AppBar> </Page.BottomAppBar>
Step 2: Show the menu pop up
When a user clicks the Sort command button on the AppBar, you show a Popup menu. The user picks a sort option from the menu.
- Create a Popup to host the sort menu.
- Set the Popup.IsLightDismissEnabled property to true.
With light dismiss enabled, the Popup hides automatically when the user interacts with another part of the app.
- Create a panel as the root of the menu UI.
- Add command buttons to the menu UI.
- Add the menu root panel as the Popup content.
- Calculate the placement of the Popup menu.
Here, we place the Popup in the bottom right corner of the screen, above the AppBar, with a padding of 4.
- Open the Popup.
Related topics
Build date: 11/29/2012
