BindableApplicationBar.BindableApplicationBar.Attach C# (CSharp) Method

Attach() public method

Attaches the BindableApplicationBar to the specified page, creating the ApplicationBar if required and adding the buttons and menu items specified in the Buttons and MenuItems properties.
public Attach ( PhoneApplicationPage parentPage ) : void
parentPage PhoneApplicationPage The parentPage to attach to.
return void
        public void Attach(PhoneApplicationPage parentPage)
        {
            this.page = parentPage;
            this.applicationBar =
                (ApplicationBar)(//parentPage.ApplicationBar ?? 
                (parentPage.ApplicationBar = new ApplicationBar()));
            this.applicationBar.StateChanged +=
                this.ApplicationBarStateChanged;

            if (this.GetBindingExpression(DataContextProperty) == null &&
                this.DataContext == null)
            {
                this.SetBinding(
                    DataContextProperty,
                    new Binding("DataContext") { Source = this.page });
            }

            this.SynchronizeProperties();
            this.AttachButtons(this.Buttons);
            this.AttachButtons(this.buttonsSourceButtons);
            this.AttachMenuItems(this.MenuItems);
            this.AttachMenuItems(this.menuItemsSourceMenuItems);

            if (this.Buttons != null && this.Buttons.Count > 0)
            {
                this.page.Loaded += this.OnPageLoaded;                
            }
        }