private void CloseItemHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { var dragablzItem = executedRoutedEventArgs.Parameter as DragablzItem; if (dragablzItem == null) { var dependencyObject = executedRoutedEventArgs.OriginalSource as DependencyObject; dragablzItem = dependencyObject.VisualTreeAncestory().OfType <DragablzItem>().FirstOrDefault(); } if (dragablzItem == null) { throw new ApplicationException("Unable to ascertain DragablzItem to close."); } var cancel = false; if (ClosingItemCallback != null) { var callbackArgs = new ItemActionCallbackArgs <TabablzControl>(Window.GetWindow(this), this, dragablzItem); ClosingItemCallback(callbackArgs); cancel = callbackArgs.IsCancelled; } if (!cancel) { RemoveItem(dragablzItem); } }
private void WindowOnClosing(object sender, CancelEventArgs cancelEventArgs) { _windowSubscription.Disposable = Disposable.Empty; if (!ConsolidateOrphanedItems || InterTabController == null) { return; } var window = (Window)sender; var orphanedItems = _dragablzItemsControl.DragablzItems(); if (ConsolidatingOrphanedItemCallback != null) { orphanedItems = orphanedItems.Where( di => { var args = new ItemActionCallbackArgs <TabablzControl>(window, this, di); ConsolidatingOrphanedItemCallback(args); return(!args.IsCancelled); }).ToList(); } var target = LoadedInstances.Except(this) .FirstOrDefault( other => other.InterTabController != null && other.InterTabController.Partition == InterTabController.Partition); if (target == null) { return; } foreach (var item in orphanedItems.Select(orphanedItem => _dragablzItemsControl.ItemContainerGenerator.ItemFromContainer(orphanedItem))) { RemoveFromSource(item); target.AddToSource(item); } }