#Win8Dev Tutorial: Integrating Application Bar in your Windows Store apps


If you are familiar with Windows Phone applications, you might be already aware of Application Bar. Application Bar is used to provide users with quick access to an application’s most common tasks, which are basically hidden when they are not needed.

 

Today in this chapter we will learn more about Application Bar in Windows Store apps along with integration and design guidelines.

 

Introduction to Application Bar

Application bar in an application is used to provide specific commands to the user which are not needed all the time. Hence, those commands are generally kept as hidden in the application bar and when the user needs them, bring them in the foreground before accessing. On need base user can bring the application bar by right clicking in the application UI, pressing Win + Z key combination or swiping from top/bottom edges of the screen. Also, the developer can programmatically show/hide the application bar when the user interacts with some commands.

 

In general, an application bar looks similar to this:

 

Bottom Application Bar

 

There are two different application bar available for Windows Store applications named as TopApplicationBar and BottomApplicationBar. As the name suggests, the top application bar resides at the top of the screen and the bottom application bar resides at the bottom of the screen.

 

The XAML code of application bars looks as below and available under the page. You can chose whether to use top application bar or bottom application bar. If needed, you can use both of them together in a screen.

 
<!-- TopAppBar design -->
<Page.TopAppBar>
    <AppBar x:Name="topAppBar">
        <Grid>
            <!-- design your application bar here -->
            .
            .
            .
            <!-- design your application bar here -->
        </Grid>
    </AppBar>
</Page.TopAppBar>
 
<!-- BottomAppBar design -->
<Page.TopAppBar>
    <AppBar x:Name="bottomAppBar">
        <Grid>
            <!-- design your application bar here -->
            .
            .
            .
            <!-- design your application bar here -->
        </Grid>
    </AppBar>
</Page.TopAppBar>

 

 

Both the application bar shows and hides automatically based on user interaction. In case you want to add specific commands to show or hide the application bar, you can do this programmatically. The “AppBar” exposes property named “IsOpen”. You can set it to True/False based on the requirement to show/hide it respectively.

 

Application Bar Properties

 

There is an other property named “IsSticky”. By default it is set to false, that means, if click inside the application window when the app bar is open, it closes automatically. If you explicitly set that property to true, it will not hide the application bar until you set the IsOpen=”False” or the user right clicks in the application window.

 

Application Bar Design Guidelines

Here are few application bar design guidelines which you want to remember while developing a Windows Store application with integrated application bar:

    • Distinct command groups in opposite side of the application bar.
    • Use separator to distinguish two or more set of groups.
    • Follow proper placement position of the application bar buttons.
    • Show commands contextually on an app bar when an item is selected, and show the app bar automatically.
    • Set the app bar's dismissal mode to sticky when displaying contextual commands.
    • Use menus and flyouts when you have too many commands.
    • Design you app bar for snap view and portrait view.
    • Use the bottom bar for default commands and top bar for navigation purposes.
    • Use the built-in icons for app bar commands.
    • Don’t put the login, logout and other account management commands in app bar.
    • Don’t put settings in the application bar.

The above list is collected from the MSDN Guidelines Page for Windows Store Application Bar and you can follow that link to know more about the design guidelines of application bar for Windows Store.

 

Integrating Application Bar in Windows Store apps

Let us start integrating a top app bar and a bottom app bar into our Windows Store application. To do this, first we will design our main application page to hold the application bar properly. As the application bar resides under the main page tag, we will add the above code and design it as below:

 
<!-- TopAppBar Design -->
<Page.TopAppBar>
    <AppBar x:Name="topAppBar" IsSticky="True" Background="Black">
        <Grid>
            <StackPanel Orientation="Horizontal">
                <Button Style="{StaticResource ClockAppBarButtonStyle}"/>
                <Button Style="{StaticResource ContactInfoAppBarButtonStyle}"/>
                <Button Style="{StaticResource CommentAppBarButtonStyle}"/>
            </StackPanel>
        </Grid>
    </AppBar>
</Page.TopAppBar>
 
<!-- BottomAppBar Design -->
<Page.BottomAppBar>
    <AppBar x:Name="bottomAppBar" Background="Black">
        <Grid>
            <StackPanel Orientation="Horizontal">
                <Button Style="{StaticResource FlagAppBarButtonStyle}"/>
                <Button Style="{StaticResource FavoriteAppBarButtonStyle}"/>
                <Button Style="{StaticResource GoAppBarButtonStyle}"/>
            </StackPanel>
        </Grid>
    </AppBar>
</Page.BottomAppBar>

 

 

You can see that, there are two app bars added in the page (as shown in the above code snippet) and in each app bar we will add a StackPanel with few buttons and add styles to those buttons. By default, the Visual Studio templates for Windows Store applications generates a lot of styles to be used in application bar but those are kept as commented.

 

You can find those styles commented in the “StandardStyles.xaml” file present in the “Common” folder as shown in the below screenshot:

 

Standard Styles for Windows Store apps

 

If you open the file, you will find those styles grouped in various section in that file as shown below:

 

Styles for Windows Store apps Application Bar

 

To enable these styles, select each group and uncomment them one by one as per your requirement. Once you uncomment, you will see them listed for Button style.

 

Now once you designed your application bars, build and run the project.  Right click on the application UI to see the application bars in the screen. To programmatically show/hide the application bar on specific command raise, set the IsOpen property respectively and in case you want to handle the sticky status, you can set the IsSticky property properly.

 

Now, once you run your application, you will be able to show, hide each application bar separately on click of different button. Our demo application will load the application as below:

 

Windows Store apps Application Bar Demo

 

End Note

I hope that this post will be useful for you to learn and integrate the application bar in your Windows Store metro application. In case any queries, please let me know. Subscribe to my blog’s RSS Feed and email newsletter to get updates directly to your inbox.

 

I am also available in Twitter, Facebook and Google+ so connect with me there for technical updates and discussions on any topic. Happy Coding.

 

Recommended Reading


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

5 comments

  1. My I recommend: http://blog.jerrynixon.com/2012/10/walkthrough-windows-8-appbar-you-might.html

    ReplyDelete
  2. Thanks Jerry for the recommendation. Added the link in the post.

    ReplyDelete
  3. Sir, Do you have any idea how can we do so as shown in this article .
    http://msdn.microsoft.com/en-us/library/windows/apps/jj150602.aspx
    I've tried but not able to find it.
    I want to use the same MenuFlayout.

    ReplyDelete
    Replies
    1. Hi Neetu,

      The article itself demonstrates how to use MenuFlyout in AppBar. Check it out.

      Delete
  4. I know Sir, But i was asking about command bar and AppBarButton tag in XAML.
    if i write following code in Page.BottomAppBar Section


    ....


    then it shows some error like missing assembly or reference. :(

    ReplyDelete


 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top