BindableApplicationBar.BindableApplicationBar.Detach C# (CSharp) Method

Detach() public method

Detaches from the specified page, removing all the buttons and menu items specified in the Buttons and MenuItems properties.
Note: The code in this method has not been tested and is likely not to work properly, will possibly raise exceptions and leak memory.
public Detach ( PhoneApplicationPage parentPage ) : void
parentPage PhoneApplicationPage The parentPage.
return void
        public void Detach(PhoneApplicationPage parentPage)
        {
            if (parentPage != this.page)
            {
                throw new InvalidOperationException();
            }

            if (this.page != parentPage)
            {
                return;
            }

            var binding = this.GetBindingExpression(DataContextProperty);

            if (binding != null &&
                binding.ParentBinding.Source == this.page)
            {
                this.DataContext = null;
            }

            this.DetachButtons(this.buttonsSourceButtons);
            this.DetachButtons(this.Buttons);
            this.DetachMenuItems(this.menuItemsSourceMenuItems);
            this.DetachMenuItems(this.MenuItems);

            this.applicationBar.StateChanged -=
                this.ApplicationBarStateChanged;
            this.applicationBar = null;
        }
        #endregion