private static void AddToQATExecuted(object sender, ExecutedRoutedEventArgs args) { var ribbon0 = (MyRibbon)sender; object model = AttachedProperties.GetModel(ribbon0); if ((model is PrimaryRibbonModel primary)) { if (!(MyRibbon.FindElementThatCanBeAddedToQAT((DependencyObject)(args.OriginalSource as UIElement)) is UIElement thatCanBeAddedToQat)) { return; } RibbonQuickAccessToolBarCloneEventArgs barCloneEventArgs = new RibbonQuickAccessToolBarCloneEventArgs(thatCanBeAddedToQat); thatCanBeAddedToQat.RaiseEvent((RoutedEventArgs)barCloneEventArgs); MyRibbon ribbon = RibbonControlService.GetRibbon((DependencyObject)thatCanBeAddedToQat) as MyRibbon; if (barCloneEventArgs.CloneInstance == null) { return; } primary.QuickAccessToolBar.Items.Add((object)barCloneEventArgs.CloneInstance); args.Handled = true; } }