1
votes

When a pivot item is changed in my Windows Phone 8.1 app page, I need to change the AppBar at the bottom of the page. All examples that I've found around this are related to the Silverlight Windows Phone 7/8 apps and don't apply to the Universal App 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
You can take a look at this question.Romasz
Thanks @Romasz - I was hoping I could do it in the designer and then just show/hide the appropriate one. Are you saying this is not possible and you have to create the AppBars programmatically at runtime?RichC
It is possible to create AppBar (CommandBars) at runtime - but AFAIK you will have to do it programmatically in code (not in xaml). As I've tried in XAML with resources it didn't work. You can prepare few commandBars is code and then switch them.Romasz
@Romasz ok, I think that gives what I needed to know! thanks!RichC
You can create the CommandBars in XAML as Resources, and assign any of them to Page.BottomAppBar when the pivot item changes in code-behind.K Mehta

1 Answers

1
votes

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;
    }
}