Search code examples
windows-phone-7panorama-controlappbar

AppBar in WP7.5 Panorama page


I'm currently developing a Windows Phone 7.5 app with a panorama page.
At the panorama page, I'm implementing an appbar to deal with several things in the app, such as displaying phone location in a Bing Map which is located in one of the panorama page items.

Now, I believe I have two options, but I don't know how they would work (if they even do work...):

  1. Show only appbar icons relevant to current page/item
  2. If you're not at the respective page/item, redirect to the page/item when clicking the appbar icon.

Would any of these actually work? Could I set an ID for each of the panorama items, and then make either 1 or 2 to work?

Thanks :)


Solution

  • Both are possible to accomplish.

    For showing only the appbar icons relevent to the page you can use the Panorama.SelectionChanged Event:

    var currentPanormaItem = ((Panorama)sender).SelectedItem
    
    if(currentPanormaItem.Equals(firstPageItem))
    {
        // Set AppBar icons for first page
    }
    else if(currentPanormaItem.Equals(secondPageItem))
    {
        // Set AppBar icons for secondpage
    }
    

    If you know which panorama item is selected you can set the appbar icon accordingly.

    Changing the selected item of a Panorama can be accomplished like this:

    panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];
    

    Though changing the selected index of a Panorama is possible, I would advise using a Pivot control. With a Pivot control it is easier to keep track of the selected item and you get a nice animation when you programatically switch the selected page.