Can I show the application bar for only one Pivot item?

In a Windows Phone 7 application, I use Pivot for the user interface. Since one of the elements of the Pivot XAML page is inserted, like:

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

The application panel - a standard template - is used only on this page, since it does not need the entire Pivot. But that does not work. At the moment, I could either activate the panel for each Pivot element, or use it for a separate non-variable page.

+7
source share
4 answers

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

Assign a PivotItem name:

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

In code:

 private void pivotMain_LoadingPivotItem(object sender, PivotItemEventArgs e) { if (e.Item == myPivotItem) ApplicationBar.IsVisible = true; else ApplicationBar.IsVisible = false; } 
+11
source

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

You can do this by specifying various application panels in the 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 handle the SelectionChanged event in your 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]; } 
+13
source

Try this ... add the following function to your xaml.cs PivotPage file and make sure you add the SelectionChanged event to use this function ...

 private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) { switch (((Pivot)sender).SelectedIndex) { case 0: ApplicationBar.IsVisible = true; break; case 1: ApplicationBar.IsVisible = false; break; } } 

Change the case based on the summary positions you want to display in the application bar. Works for me and handles minimizing the application bar.

+3
source

While it is possible to load ApplicationBar only when a specific PivotItem is displayed, this is non-standard behavior. As a rule, it is usually not good to surprise the user with non-standard behavior.

What you're trying to do is suggest that a different architecture for your application might be more appropriate. If you really have to do it this way, make sure you understand: the reasons why this is not done at all; the consequences of this; what are the alternatives; and why the alternatives do not fit.

+2
source

All Articles