为不同的Widdows Phone Pivot Page添加不同ApplicationBar
XAML代码:
<phone:phoneapplicationpage .Resources> <shell:applicationbar x:Key="AppBar0" IsMenuEnabled="True" IsVisible="True" Mode="Default" Opacity="0.8" BackgroundColor="Black" ForegroundColor="White"> <shell:applicationbariconbutton x:Name="HotTopicsRefreshButton" Text="刷新" IconUri="/Assets/Icons/refresh.png" Click="HotTopicsRefreshButton_Click"></shell:applicationbariconbutton> <shell:applicationbariconbutton x:Name="HotTopicsSearchButton" Text="搜索" IconUri="/Assets/Icons/feature.search.png" Click="SearchButton_Click"></shell:applicationbariconbutton> </shell:applicationbar><shell:applicationbar .MenuItems> <shell:applicationbarmenuitem Text="设置" Click="SettingsButton_Click"></shell:applicationbarmenuitem> </shell:applicationbar> <shell:applicationbar x:Key="AppBar1" BackgroundColor="Black" ForegroundColor="White" IsMenuEnabled="True" IsVisible="True" Mode="Default" Opacity="0.8"> <shell:applicationbariconbutton Text="管理" IconUri="/Assets/Icons/favs.png" Click="ManageSubwordsBtn_Click"></shell:applicationbariconbutton> <shell:applicationbariconbutton Text="刷新" IconUri="/Assets/Icons/refresh.png"></shell:applicationbariconbutton> <shell:applicationbariconbutton Text="搜索" IconUri="/Assets/Icons/feature.search.png" Click="SearchButton_Click"></shell:applicationbariconbutton> </shell:applicationbar><shell:applicationbar .MenuItems> <shell:applicationbarmenuitem Text="设置" Click="SettingsButton_Click"></shell:applicationbarmenuitem> </shell:applicationbar> </phone:phoneapplicationpage>
以下是.cs代码:
if (PhonePivot.SelectedIndex == 0)
{
ApplicationBar = (IApplicationBar)Resources[“AppBar0”];
}
else if (PhonePivot.SelectedIndex == 1)
{
ApplicationBar = (IApplicationBar)Resources[“AppBar1”];
}
if (ApplicationBar != null)
{
ApplicationBar.BackgroundColor = System.Windows.Media.Colors.Black;
ApplicationBar.ForegroundColor = System.Windows.Media.Colors.White;
}