private void CreateTab() { TabHeaderControl tabHeader = new TabHeaderControl(); WITSMLControl singleClient = new WITSMLControl(tabHeader); tabHeader.CloseAction = CloseTab; TabItem tabItem = new TabItem(); tabItem.Content = singleClient; tabItem.Header = tabHeader; int tabItemIndex = MainTabControl.Items.Count - 1; MainTabControl.Items.Insert(tabItemIndex, tabItem); MainTabControl.SelectedIndex = tabItemIndex; }
private void CloseTab(TabHeaderControl tabHeader) { for (int i = 0; i < MainTabControl.Items.Count; i++) { TabItem item = MainTabControl.Items.GetItemAt(i) as TabItem; TabHeaderControl tabHeaderControl = item.Header as TabHeaderControl; if (tabHeaderControl != null && tabHeaderControl == tabHeader) { if (i != 0) { if (MainTabControl.SelectedIndex == i) { MainTabControl.SelectedIndex = i - 1; } } MainTabControl.Items.RemoveAt(i); break; } } }