1

当我的 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>
4

1 回答 1

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;
    }
}
于 2014-06-03T05:06:59.517 回答