BindableApplicationBar.BindableApplicationBarButton.Detach C# (CSharp) Method

Detach() public method

Detaches the associated ApplicationBarIconButton from the ApplicationBar and from this instance.
public Detach ( ) : void
return void
        public void Detach()
        {
            this.applicationBarIconButton.Click -=
                this.ApplicationBarIconButtonClick;
            this.applicationBar.Buttons.Remove(
                this.applicationBarIconButton);
            this.applicationBar = null;
            this.applicationBarIconButton = null;
        }

Usage Example

        private void DetachButton(BindableApplicationBarButton button)
        {
            if (button.GetBindingExpression(DataContextProperty) == null &&
                button.GetValue(DataContextProperty) == this.DataContext)
            {
                button.DataContext = null;
            }

            button.Detach();
        }