Search code examples
c#windows-phone-8application-barpivotitem

How do i handle the event of a selected pivot item in Windows Phone


I have an app with 3 PivotItems and an ApplicationBar. I want to hide the ApplicationBar when the PivotItems 2 and 3 are selected, and show the ApplicationBar when the first PivotItem is selected.


Solution

  • I don't know why this question has been down voted. The question sense may be wrong and it can be edited. I got the solution for you @user3847141. Here you go.

    PivotItem pivot = null;
        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ApplicationBar appBar = new ApplicationBar();
            ApplicationBarIconButton appBarIconButton = new ApplicationBarIconButton();
            pivot = (PivotItem)(sender as Pivot).SelectedItem;
            switch(pivot.Header.ToString())
            {
                case "item1": 
                    appBar.Mode = ApplicationBarMode.Default;
                    appBarIconButton.IconUri = new Uri("/appbar.close.png", UriKind.RelativeOrAbsolute);
                    appBarIconButton.Text = "Close";
                    appBar.Buttons.Add(appBarIconButton);
                    this.ApplicationBar = appBar;
                    break;
                case "item2":
                    appBar.Mode = ApplicationBarMode.Minimized; // To minimize AppBar
                    appBar = null; // Delete Application Bar                     
                    this.ApplicationBar = appBar;
                    break;
                case "item3":
                    appBar.Mode = ApplicationBarMode.Minimized;
                    appBar = null;                   
                    this.ApplicationBar = appBar;
                    break;
            }
        }
    

    You can achieve this through Selection_Changed event in Pivot. Hope it helps.