/// <summary> /// remove a tabItem /// </summary> /// <param name="tabItem"></param> public void RemoveItem(TabItemEx tabItem) { var c = new TabItemExCancelEventArgs(tabItem); TabItemClosing.SafeFire(new object[] { c }); //if the itemssource is using if (this.ItemsSource != null) { IList list = this.ItemsSource as IList; if (list == null) { return; } //get the data item var item = ItemContainerGenerator.ItemFromContainer(tabItem); if (item == null) { return; } list.Remove(item); } else { this.Items.Remove(tabItem); } TabItemClosed.SafeFire(new object[] { c }); }
public void CloseTabItem() { DependencyObject obj = this; while (true) { obj = VisualTreeHelper.GetParent(obj); if (obj is TabControl tabControl) { try { TabItemClosed?.Invoke(obj, new EventArgs()); tabControl.Items.Remove(this); } catch (Exception) { } break; } } }