Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide an Application Bar on certain Pivot Pages in Windows Phone 8

I think this has a trivial answer but I'm not getting it. Basically I have a Windows Phone 8 app that contains a Pivot, and application bar. I want to hide the application bar when a certain page in the Pivot is navigated to.

What I did was add the following code in the Pivot_SelectionChanged event:

AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2);

So when the 3rd page is shown, the Application Bar is hidden, and should be shown when the 3rd page is navigated away from. However, when I run the app, I get a NullReference error for the AppBar.

I tried to put it inside Dispatcher.BeginInvoke:

Dispatcher.BeginInvoke(() => {    
      AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2);
});

It works for the first few swipes, but on causes a NullReference exception on the third page.

Am I totally on the wrong track or is there an easier way to do this?

like image 915
Devmonster Avatar asked Jan 13 '23 11:01

Devmonster


1 Answers

Don't use the name given by you to the ApplicationBar, use ApplicationBar property of the page instead:

ApplicationBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2);

i.e. Replace AppBar with ApplicationBar

like image 80
anderZubi Avatar answered Jan 31 '23 00:01

anderZubi