/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private void OnRemoveFromQatButtonClick(object sender, RoutedEventArgs e) { // Remove the item from the list int selectedIndex = qatItemsListBox.SelectedIndex; RibbonControlReference controlRef = (RibbonControlReference)qatItemsListBox.SelectedItem; qatItems.RemoveAt(selectedIndex); // Dispose the cloned item if it is not already in the real QAT if (!this.Ribbon.QuickAccessToolBarItems.Contains(controlRef.Control)) { CloneService.DisposeClone(controlRef.Control); } this.UpdateButtons(); }
/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private void OnAddToQatButtonClick(object sender, RoutedEventArgs e) { // Ensure that the control has not already been added RibbonControlReference controlRef = (RibbonControlReference)availableQatItemsListBox.SelectedItem; if (controlRef.IsAlreadyAdded(qatItems)) { MessageBox.Show("The selected command is already on the Quick Access Toolbar.", "Quick Access Toolbar", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } // Clone the selected control and add it to the QAT items list UIElement clonedControl = controlRef.Clone(); qatItems.Insert(qatItemsListBox.SelectedIndex + 1, new RibbonControlReference(clonedControl)); qatItemsListBox.SelectedIndex = qatItemsListBox.SelectedIndex + 1; }