How to Programatically Create ApplicationBar in Windows Phone ?

Published on December 27, 2013 by abundantcode

Filed under Windows Phone

Last modified December 27, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 4 (1 votes)

This article have been viewed 3455 times

Are you looking to create ApplicationBar programmatically at runtime in Windows Phone ? .

Below is a sample code snippet that demonstrates how to create Application Bar in Windows Phone 8 .

How to Programatically Create ApplicationBar in Windows Phone ?

 public void CreateApplicationBar()
 {
           var MainApplicationBar = new ApplicationBar();
           ApplicationBarIconButton appBarIconButton = new ApplicationBarIconButton(new Uri("/Assets/Add.png",UriKind.RelativeOrAbsolute));
           appBarIconButton.Text = "Save";
           MainApplicationBar.Buttons.Add(appBarIconButton);

           ApplicationBarIconButton appBarIconButtonCancel = new ApplicationBarIconButton(new Uri("/Assets/cancel.png", UriKind.RelativeOrAbsolute));
           appBarIconButtonCancel.Text = "Cancel";
           MainApplicationBar.Buttons.Add(appBarIconButtonCancel);

           ApplicationBarMenuItem menuitem1 = new ApplicationBarMenuItem("About Abundantcode");
           MainApplicationBar.MenuItems.Add(menuitem1);
           this.ApplicationBar = MainApplicationBar;
 }

Call this function in the constructor of the page after the InitializeComponent method.

public MainPage()
{
            InitializeComponent();
            CreateApplicationBar();
}

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to delete user account from command line in Windows 10 ?

You can delete a user account from command line in Windows 10 using the net user command and specify...

How to add new user account from command line in Windows 10 ?

You can add a new user account in Windows 10 using command prompt using the net user command and pas...

How to open display settings from command line in Windows 10 ?

The display properties can be found in the settings app in Windows 10 which lets the users to config...