2 out of 2 rated this helpful - Rate this topic

ApplicationBar Class

July 26, 2012

Represents an Application Bar in Windows Phone applications.

System.Object
  Microsoft.Phone.Shell.ApplicationBar

Namespace:  Microsoft.Phone.Shell
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
XMLNS for XAML: Not mapped to an xmlns.
[ContentPropertyAttribute("Buttons")]
public sealed class ApplicationBar : IApplicationBar
<ApplicationBar>
  Buttons
</ApplicationBar>

The ApplicationBar type exposes the following members.

  NameDescription
Public methodApplicationBarCreates a new instance of the ApplicationBar class.
Top
  NameDescription
Public propertyBackgroundColorGets or sets the background color of the Application Bar.
Public propertyButtonsGets the list of icon buttons that appear on the Application Bar.
Public propertyDefaultSizeGets the distance that the Application Bar extends into a page when the Mode property is set to Default.
Public propertyForegroundColorGets or sets the foreground color of the Application Bar.
Public propertyIsMenuEnabledGets or sets a value that indicates whether the user sees the (optional) menu items when they click the ellipsis to expand the Application Bar.
Public propertyIsVisibleGets or sets a value that indicates whether the Application Bar is visible.
Public propertyMenuItemsGets the list of the menu items that appear on the Application Bar.
Public propertyMiniSizeGets the distance that the Application Bar extends into a page when the Mode property is set to Minimized.
Public propertyModeGets or sets the size of the Application Bar.
Public propertyOpacityGets or sets the opacity of the Application Bar.
Top
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Top
  NameDescription
Public eventStateChangedOccurs when the user opens or closes the Application Bar by clicking the ellipsis.
Top

An Application Bar contains between one and four buttons, an ellipsis, and a set of text menu items. For more information, see Application Bar Overview for Windows Phone.

The following example creates an Application Bar in XAML that has two icon buttons and two menu items. For the full example, see How to: Create an Application Bar in XAML for Windows Phone.

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar Mode="Default" Opacity="1.0" IsMenuEnabled="True" IsVisible="True">

        <shell:ApplicationBarIconButton Click="Save_Click" IconUri="/Images/save.png" Text="save" />
        <shell:ApplicationBarIconButton Click="Settings_Click" IconUri="/Images/settings.png" Text="settings" />

        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Click="MenuItem1_Click" Text="menu item 1" />
            <shell:ApplicationBarMenuItem Click="MenuItem2_Click" Text="menu item 2" />
        </shell:ApplicationBar.MenuItems>

    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

The following example creates an Application Bar in code that has one icon button and one menu item. For the full example, see How to: Create an Application Bar in Code for Windows Phone.

using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace HowToCS
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            ApplicationBar = new ApplicationBar();

            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.Opacity = 1.0; 
            ApplicationBar.IsVisible = true;
            ApplicationBar.IsMenuEnabled = true;

            ApplicationBarIconButton button1 = new ApplicationBarIconButton();
            button1.IconUri = new Uri("/Images/YourImage.png", UriKind.Relative);
            button1.Text = "button 1";
            ApplicationBar.Buttons.Add(button1);
            button1.Click += new EventHandler(button1_Click);

            ApplicationBarMenuItem menuItem1 = new ApplicationBarMenuItem();
            menuItem1.Text = "menu item 1";
            ApplicationBar.MenuItems.Add(menuItem1);
            menuItem1.Click += new EventHandler(menuItem1_Click);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Button 1 works!");
            //Do work for your application here.
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Menu item 1 works!");
            //Do work for your application here.
        }
    }
}

The following example creates an Application Bar that can be reused on multiple pages in your application. For the full example, see How to: Reuse an Application Bar on Multiple Pages in Your Windows Phone Application.

<Application.Resources>

    <shell:ApplicationBar x:Key="GlobalAppBar" IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" Click="Button1_Click" />
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2" Click="Button2_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1" Click="MenuItem1_Click" />
            <shell:ApplicationBarMenuItem Text="MenuItem 2" Click="MenuItem2_Click" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>

</Application.Resources>

The following example creates two Application Bars that can be used in a single pivot control in your application. For the full example, see How to: Use Different Application Bars in a Single Pivot Control in Your Windows Phone Application.

<Application.Resources>

    <shell:ApplicationBar x:Key="AppBar1" IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" Click="Button1_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1" Click="MenuItem1_Click" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>

    <shell:ApplicationBar x:Key="AppBar2" IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" Click="Button1_Click" />
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2" Click="Button2_Click" />
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1" Click="MenuItem1_Click" />
            <shell:ApplicationBarMenuItem Text="MenuItem 2" Click="MenuItem2_Click" />
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
        
</Application.Resources>

Windows Phone OS

Supported in: 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.