如何在Window Phone 8.1中更改PivotItem上的xaml AppBar更改

时间:2014-05-18 17:52:30

标签: c# windows-phone-8.1 win-universal-app

在我的Windows Phone 8.1应用页面中更改透视图项目后,我需要更改页面底部的AppBar。我发现的所有示例都与Silverlight Windows Phone 7/8应用程序有关,不适用于通用应用程序Windows Phone 8.1。

<AppBar x:Name="AppBar1" Visibility="Visible">
    <CommandBar>
        <AppBarButton x:Name="Save" Icon="save" Label="Save" Click="AppBarButton_Click" />
        <AppBarButton x:Name="Cancel" Icon="cancel" Label="Cancel" Click="AppBarButton_Click" />
    </CommandBar>
</AppBar>

<AppBar x:Name="AppBar2" Visibility="Collapsed">
    <CommandBar x:Name="AppBar2">
        <AppBarButton x:Name="Add" Icon="save" Label="Add" Click="AppBarButton_Click" />
    </CommandBar>
</AppBar>

1 个答案:

答案 0 :(得分:1)

<强> XAML

<Pivot x:Name="Pivot" SelectionChanged="Pivot_SelectionChanged">
</Pivot>

<强> C#

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    int no = Pivot.SelectedIndex; 
    if(no == 0)  
    {
        AppBar1.Visibility = Visibility.Visible;
        AppBar2.Visibility = Visibility.Collapsed;
    }
    else  
    {
        AppBar1.Visibility = Visibility.Collapsed;
        AppBar2.Visibility = Visibility.Visible;
    }
}