How to Programatically Create ApplicationBar in Windows Phone ?

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();
}