private static void OnRemoveCommandExecute(object obj) { var parameters = obj as object[]; var tabItem = parameters[0] as TabItem; var tabControl = parameters[1] as TabControl; var dataObject = tabControl.ItemContainerGenerator.ItemFromContainer(tabItem); var result = TabControlHelper.RaiseItemRemoving(tabControl, dataObject); if (!result) { return; } else { bool hasRemovedFromSource = false; if (dataObject is TabItem) { try { tabControl.Items.Remove(tabItem); hasRemovedFromSource = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } TabControlHelper.RaiseItemRemoved(tabControl, dataObject, hasRemovedFromSource); } }
public void Execute(object parameter) { var values = (object[])parameter; var tabItem = values[0] as TabItem; var tabControl = values[1] as TabControl; if (tabItem != null && tabControl != null) { var isVertical = tabItem.TabStripPlacement == Dock.Top || tabItem.TabStripPlacement == Dock.Bottom; tabItem.IsSelected = false; var anima1 = new DoubleAnimation() { From = isVertical ? tabItem.ActualWidth : tabItem.ActualHeight, To = 0, Duration = TimeSpan.FromSeconds(0.3), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }, }; anima1.Completed += delegate { IEditableCollectionView items = tabControl.Items; //Cast to interface if (items.CanRemove) { items.Remove(tabItem); } TabControlHelper.RaiseRemoved(tabControl, tabItem, items.CanRemove); }; var anima2 = new DoubleAnimation() { To = 0, Duration = TimeSpan.FromSeconds(0.3), }; tabItem.BeginAnimation(isVertical ? TabItem.WidthProperty : TabItem.HeightProperty, anima1); tabItem.BeginAnimation(TabItem.OpacityProperty, anima2); } }