App.xaml:
<Application.Resources>
<shell:ApplicationBar x:Key=”MainAppBar” IsVisible=”True”>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text=”About” Click=”ApplicationBarAbout_Click”></shell:ApplicationBarMenuItem>
</shell:ApplicationBar.MenuItems>
<shell:ApplicationBar.Buttons>
<shell:ApplicationBarIconButton Text=”Web” IconUri=”ie_icon.png” Click=”ApplicationBarIconWebBrowserButton_Click”></shell:ApplicationBarIconButton>
<shell:ApplicationBarIconButton Text=”Images” IconUri=”pictures_Icon.png” Click=”ApplicationBarIconPictures_Click” ></shell:ApplicationBarIconButton>
</shell:ApplicationBar.Buttons>
</shell:ApplicationBar>
</Application.Resources>
App.xaml.cs:所寫的方法是通用的,當你進入到任何一個頁面中,點擊ApplicationBar的按鈕,都能執行到這些代碼
private void ApplicationBarIconWebBrowserButton_Click(object sender, EventArgs e)
{
PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigate(new Uri("/WebBrowser/www.bin.com", UriKind.Relative));
}
private void ApplicationBarIconPictures_Click(object sender, EventArgs e)
{
PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigate(new Uri("/Pictures",UriKind.Relative));
}
private void ApplicationBarAbout_Click(object sender, EventArgs e)
{
PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigate(new Uri("/About",UriKind.Relative));
}
MainPage.xaml:
<phone:PhoneApplicationPage ApplicationBar=”{StaticResource MainAppBar}” >