Question: I'm trying to create a Pivot control, and to eatch item of the Pivot control I want to assosiate a different ApplicationBar. I tried to follow [this](http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394036%28v=vs.105%29.aspx) walkthrough in MSDN, but it seems to be that there is an error in this code:

```
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        switch (((Pivot)sender).SelectedIndex)
        {
            case 0:
                ApplicationBar  = ((ApplicationBar)Application.Current.Resources["CountingAppBar"]);
                break;

            case 1:
                ApplicationBar  = ((ApplicationBar)Application.Current.Resources["SavingAppBar"]);
                break;
        }
    }

```

The error is that ApplicationBar is a class and it's used as variable, so I tried to create an instance before the switch statement, here is what I did:

```
private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ApplicationBar appBar;
        switch (((Pivot)sender).SelectedIndex)
        {
            case 0:
                appBar = ((ApplicationBar)Application.Current.Resources["CountingAppBar"]);
                break;

            case 1:
                appBar = ((ApplicationBar)Application.Current.Resources["SavingAppBar"]);
                break;
        }
    }

```

But it doesn't seem to work.
My level in programming is still a beginner, it would be appreciated if the answer is detailed.
Thank you.

Answer: 
<http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394044%28v=vs.105%29.aspx>

Why don't you use just one ApplicationBar and add or remove ApplicationBarButtons based on the selected Pivot control? Should be pretty straightforward considering that many apps do it.

PS: From personal experience, add your application bar via code in C#...I have faced issues while changing XAML app bars.
Hey seems to be quite late but i followed the same msdn tutorial. you may not be getting the required result as you need to attach a selection changed event with the pivot item. 

```
<controls:Pivot SelectionChanged="Pivot_SelectionChanged_2" >

</controls:Pivot>

```