private void tabControl_TabItemClosing(object sender, TabItemCancelEventArgs e) { if(e.TabItem.Content is IDisposable) (e.TabItem.Content as IDisposable).Dispose(); e.TabItem.Content = null; // set no parent }
/// <summary> /// Called by a child Header that wants to remove itself by clicking on the close button /// </summary> /// <param name="tabItem"></param> public void RemoveTabItem(TabItem tabItem) { if (IsFixedSize) { throw new InvalidOperationException("ItemsSource is Fixed Size"); } // gives an opertunity to cancel the removal of the tabitem var c = new TabItemCancelEventArgs(tabItem); if (TabItemClosing != null) { TabItemClosing(tabItem, c); } if (c.Cancel) { return; } if (ItemsSource != null) { var list = ItemsSource as IList; object listItem = ItemContainerGenerator.ItemFromContainer(tabItem); if (listItem != null && list != null) { list.Remove(listItem); } } else { this.Items.Remove(tabItem); } if (TabItemClosed != null) { TabItemClosed(this, new TabItemEventArgs(tabItem)); } }
/// <summary> /// Called by a child Header that wants to remove itself by clicking on the close button /// </summary> /// <param name="tabItem"></param> public void RemoveTabItem(TabItem tabItem) { //int index = 0; if (IsFixedSize) throw new InvalidOperationException("ItemsSource is Fixed Size"); // gives an opertunity to cancel the removal of the tabitem var c = new TabItemCancelEventArgs(tabItem); if (TabItemClosing != null) TabItemClosing(tabItem, c); if (c.Cancel) return; switch (tabItem.Header.ToString()) { case "Work in Progress": isAdded.Set((int)Section.WIP, false); break; case "Inventory": isAdded.Set((int)Section.INV, false); break; case "In-/OutBound": isAdded.Set((int)Section.INOUT, false); break; case "Outbound": isAdded.Set((int)Section.OUTBOUND, false); break; case "Inbound": isAdded.Set((int)Section.INBOUND, false); break; case "Return": isAdded.Set((int)Section.RETURN, false); break; case "Dock": isAdded.Set((int)Section.DOCK, false); break; case "Reporting": isAdded.Set((int)Section.REPORT, false); break; case "Tasks": isAdded.Set((int)Section.TASKS, false); break; case "Billing": isAdded.Set((int)Section.BILL, false); break; case "Admin": isAdded.Set((int)Section.ADMIN, false); break; default: break; } if (ItemsSource != null) { var list = ItemsSource as IList; object listItem = ItemContainerGenerator.ItemFromContainer(tabItem); //index = ItemContainerGenerator.IndexFromContainer(tabItem); if (listItem != null && list != null) list.Remove(listItem); } else this.Items.Remove(tabItem); if (TabItemClosed != null) { TabItemClosed(this, new TabItemEventArgs(tabItem)); //isAdded.Set(index, false); //for (int i = 0; i < numOfOptions; i++) //{ // if (seqArray[i] >= //indexOfTabs)//*********************** // seqArray[i] = -1; //} //indexOfTabs--;//reduce number of tabs counter } }
/// <summary> /// Called by a child Header that wants to remove itself by clicking on the close button /// </summary> /// <param name="tabItem"></param> public void RemoveTabItem(TabItem tabItem) { if (IsFixedSize) throw new InvalidOperationException("ItemsSource is Fixed Size"); // gives an opertunity to cancel the removal of the tabitem var c = new TabItemCancelEventArgs(tabItem); if (TabItemClosing != null) TabItemClosing(tabItem, c); if (c.Cancel) return; if (ItemsSource != null) { var list = ItemsSource as IList; object listItem = ItemContainerGenerator.ItemFromContainer(tabItem); if (listItem != null && list != null) list.Remove(listItem); } else this.Items.Remove(tabItem); if (TabItemClosed != null) TabItemClosed(this, new TabItemEventArgs(tabItem)); }
/// <summary> /// Called by a child Header that wants to remove itself by clicking on the close button /// </summary> /// <param name="tabItem"></param> public void RemoveTabItem(TabItem tabItem) { //int index = 0; if (IsFixedSize) { throw new InvalidOperationException("ItemsSource is Fixed Size"); } // gives an opertunity to cancel the removal of the tabitem var c = new TabItemCancelEventArgs(tabItem); if (TabItemClosing != null) { TabItemClosing(tabItem, c); } if (c.Cancel) { return; } switch (tabItem.Header.ToString()) { case "Work in Progress": isAdded.Set((int)Section.WIP, false); break; case "Inventory": isAdded.Set((int)Section.INV, false); break; case "In-/OutBound": isAdded.Set((int)Section.INOUT, false); break; case "Outbound": isAdded.Set((int)Section.OUTBOUND, false); break; case "Inbound": isAdded.Set((int)Section.INBOUND, false); break; case "Return": isAdded.Set((int)Section.RETURN, false); break; case "Dock": isAdded.Set((int)Section.DOCK, false); break; case "Reporting": isAdded.Set((int)Section.REPORT, false); break; case "Tasks": isAdded.Set((int)Section.TASKS, false); break; case "Billing": isAdded.Set((int)Section.BILL, false); break; case "Admin": isAdded.Set((int)Section.ADMIN, false); break; default: break; } if (ItemsSource != null) { var list = ItemsSource as IList; object listItem = ItemContainerGenerator.ItemFromContainer(tabItem); //index = ItemContainerGenerator.IndexFromContainer(tabItem); if (listItem != null && list != null) { list.Remove(listItem); } } else { this.Items.Remove(tabItem); } if (TabItemClosed != null) { TabItemClosed(this, new TabItemEventArgs(tabItem)); //isAdded.Set(index, false); //for (int i = 0; i < numOfOptions; i++) //{ // if (seqArray[i] >= //indexOfTabs)//*********************** // seqArray[i] = -1; //} //indexOfTabs--;//reduce number of tabs counter } }