Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show Application bar for one Pivot item only?

In a Windows Phone 7 application I use a Pivot for UI. As one of the items of the Pivot a XAML page is inserted, as:

<Pivot_Item>
<myviews:a_page.xaml/>
</Pivot_Item>

An application bar - a standard template - is used within that page only, as the whole Pivot doesn't need it. But this doesn't work. For now I was only able either to activate the bar for the every Pivot item or to use it for a separate non-pivot page.

like image 742
87element Avatar asked May 15 '11 10:05

87element


2 Answers

As far as I know - ApplicationBar associated with your Page, but Pivot is just a control on your Page. So, ApplicationBar is assigned for the entire Page regardless of which Pivot tab is shown.

You can do it by defining different application bars in resources section:

<phone:PhoneApplicationPage.Resources> 

    <shell:ApplicationBar x:Key="firstPivotTabApplicationBar" IsVisible="True"> 
        ...
    </shell:ApplicationBar> 

    <shell:ApplicationBar x:Key="secondPivotTabApplicationBar" IsVisible="True"> 
        ...
    </shell:ApplicationBar> 

</phone:PhoneApplicationPage.Resources>

And processing SelectionChanged event in your pivot control:

private void MainPagePivot_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{
    string pivotResource;

    switch (_mainPagePivot.SelectedIndex)
    {
        case 0:
            pivotResource = "firstPivotTabApplicationBar";
            break;

        case 1:
            pivotResource = "secondPivotTabApplicationBar";
            break;

        default:
            throw new ArgumentOutOfRangeException();
    }

    ApplicationBar = (ApplicationBar)Resources[pivotResource]; 
} 
like image 90
oxilumin Avatar answered Nov 17 '22 00:11

oxilumin


The easiest way to do this is simply to handle the Pivot's LoadingPivotItem event.

Assign that PivotItem a name:

<Pivot_Item Name="myPivotItem">
<myviews:a_page.xaml/>
</Pivot_Item>

In the code:

private void pivotMain_LoadingPivotItem(object sender, PivotItemEventArgs e)
{
     if (e.Item == myPivotItem) 
        ApplicationBar.IsVisible = true;
     else
        ApplicationBar.IsVisible = false;  
}
like image 23
keyboardP Avatar answered Nov 17 '22 01:11

keyboardP