Windows Phone 8 - Global App Bar across all your pages
If you want to have a same App Bar across all the pages of your Windows Phone 8 app, it could be achieved by placing the code in the app level file App.xaml similar to Master Page or Global.asax.
Here are the steps to display the global app bar -
- Add the app bar markup to the App.xaml file.
App.xaml
<shell:ApplicationBar x:Key="RootAppBar" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Your Text" Click="YourText_Click">
</shell:ApplicationBarMenuItem>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
- If the menu item has a click event, then add the click event code to App.xaml.cs file.
void YourText_Click(object sender, EventArgs e)
{
// Write your click event code here.
}
- Finally, add reference to the app bar in the pages that needed an app bar. It can be done by adding ApplicationBar property and pointing it to a static resource in the global page markup. For e.g. if you would like to add a app bar on the main page, see the sample below,
MainPage.xaml
<phone:PhoneApplicationPage
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
ApplicationBar="{StaticResource RootAppBar}">
Labels: "App Bar", "Click Event", "Windows Phone 8", App.XAML, ApplicationBar, Apps, C#, CodeBehind, CSharp, Design Page, MainPage, MasterPage, Menu Item, MenuBar, Mobile, Phone, PhoneApplicationPage, StaticResource, XAML
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]