locked
Where to specify multiple appbars?

    Question

  • In my app I have a default app bar that is defined in the default.html

    However on a specific page I want a custom appbar and not the default one.

    So I added the custom appbar to the fragment of the page that is about to use it. The default app bar is hidden, in the fragment pages ready event. However when navigating back to from the fragment page the custom appbar remains in the DOM. So the next time I navigate to the fragment page with the custom app bar in it I will have 2 custom appbars.

    Whats the recommendation here to handle such cases?

    Wednesday, February 22, 2012 11:31 PM

Answers

  • I personally would only have one appbar and change the visibility of items as I need them.


    Jeff Sanders (MSFT)

    Thursday, February 23, 2012 8:24 PM
    Moderator

All replies

  • Would it be better to have both appbars in the default.html, and turn them on and off dynamically? Then your fragment can just turn on/off the appbar it needs.

    I know right now these HTML5/WinJS apps to leave fragment stuff in the DOM when you flip back and forth between fragments, hopefully something that is fixed in the Windows 8 Consumer Preview in a few weeks.

    Thursday, February 23, 2012 3:13 PM
  • I personally would only have one appbar and change the visibility of items as I need them.


    Jeff Sanders (MSFT)

    Thursday, February 23, 2012 8:24 PM
    Moderator
  • This does not work in my case, since the appbar can contain custom layouts depending on the view its displayed in.

    @Harlequin: Thanks for your answer. Time to debug into the UI code for the appbar and see why its appened to the body instead of the container its created with.


    Thursday, February 23, 2012 9:34 PM
  • But I do agree with Jeff, as the app bar is an application-wide experience. Having completely different bars wouldn't be intuitive. But like Jeff said, you can have page-specific buttons in the app bar. Example your main page might not have a Print button, but inside content pages would.

    Maybe tinker with the apps that come with the Developer Preview and see how they use the app bar. They might have some examples of app bars changing context.

    Friday, February 24, 2012 5:06 PM