title: How can I hide an Application Bar on certain Pivot Pages in Windows Phone 8
body: <p>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. </p>
  
  <p>What I did was add the following code in the <code>Pivot_SelectionChanged</code> event:</p>
  
  <pre><code>AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2);
  </code></pre>
  
  <p>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.</p>
  
  <p>I tried to put it inside <code>Dispatcher.BeginInvoke</code>:</p>
  
  <pre><code>Dispatcher.BeginInvoke(() =&gt; {    
        AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2);
  });
  </code></pre>
  
  <p>It works for the first few swipes, but on causes a NullReference exception on the third page.</p>
  
  <p>Am I totally on the wrong track or is there an easier way to do this? </p>