windows phone 中设置Application Bar
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}” >