關於爲Pivot不同的PivotItem定製ApplicationBa,原理其實很簡單,首先定義多套ApplicationBar資源
<shell:ApplicationBar x:Key="appbar1" IsVisible="True">
<shell:ApplicationBarIconButton IconUri="Images/appbar.add.rest.png" Text="Button1_1"/>
<shell:ApplicationBarIconButton IconUri="Images/appbar.back.rest.png" Text="Button1_2"/>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="appbar2" IsVisible="True">
<shell:ApplicationBarIconButton IconUri="Images/appbar.delete.rest.png" Text="Button2_1"/>
<shell:ApplicationBarIconButton IconUri="Images/appbar.next.rest.png" Text="Button2_2"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>
還可以爲不同的Button設置響應事件,這裏就略去了。
其次,讓Pivot
control響應SelectionChanged事件
事件處理函數中爲不同的PivotItem設置不同的ApplicationBar
{
if (MyPivotControl.SelectedIndex == 0)
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["appbar1"];
else if (MyPivotControl.SelectedIndex == 1)
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["appbar2"];
}
http://www.hugwp.com/article-750-1.html