private void DetachMenuItem(BindableApplicationBarMenuItem menuItem) { if (menuItem.GetBindingExpression(DataContextProperty) == null && menuItem.GetValue(DataContextProperty) == this.DataContext) { menuItem.DataContext = null; } menuItem.Detach(); }