/// <summary> /// Removes the item from the view. If the item is one of the customizable items, then it is /// collapsed, if it is an item added to the QAT from the UI, it is removed from the Items collection. /// </summary> public void Remove(object item) { if (!Items.Contains(item)) { var dp = item as DependencyObject; if (dp != null) { item = ItemContainerGenerator.ItemFromContainer(dp); if (item == null || !Items.Contains(item)) { return; } } else { return; } } var customizable = CustomizableItems.Where(c => c.Item == item).FirstOrDefault(); if (customizable != null) { customizable.Visibility = Visibility.Collapsed; } else { Items.Remove(item); } }
/// <summary> /// Overriding to setup state. /// </summary> protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); var fe = element as FrameworkElement; if (fe != null && fe != _CustomizeButton) { if (FrameworkElement.ContextMenuProperty.IsUnsetValue(fe)) { fe.SetResourceReference(FrameworkElement.ContextMenuProperty, QuickAccessToolBar.RemoveItemContextMenuKey); } // Items can be added directly by client, in which case they go into the customizable list, or // they can be added internally when user elects to add item to QAT, in which case they do // not go into the customize list. if ((bool)fe.GetValue(IsCloneProperty) == false && !(item is Separator)) { var customizeListWrapper = new CustomizableItem(item); customizeListWrapper.Visibility = fe.Visibility; customizeListWrapper.PropertyChanged += HandleCustomizableItemVisibilityChanged; fe.Bind(VisibilityProperty, customizeListWrapper, "Visibility", BindingMode.TwoWay); CustomizableItems.Add(customizeListWrapper); } } }
/// <summary> /// Overriding to ensure proper state. /// </summary> protected override void ClearContainerForItemOverride(DependencyObject element, object item) { base.ClearContainerForItemOverride(element, item); var customizable = CustomizableItems.Where(c => c.Item == item).FirstOrDefault(); if (customizable != null) { customizable.PropertyChanged -= HandleCustomizableItemVisibilityChanged; CustomizableItems.Remove(customizable); } }