private void tabControl_NewTabItem(object sender, NewTabItemEventArgs e) { _mainVM.CreateNewStrategyCodeCmd.Execute(); }
/// <summary> /// Add a new Header /// </summary> public void AddTabItem() { if (IsFixedSize) throw new InvalidOperationException("ItemsSource is Fixed Size"); int i = this.SelectedIndex; // give an opertunity to cancel the adding of the tabitem CancelEventArgs c = new CancelEventArgs(); if (TabItemAdding != null) TabItemAdding(this, c); if (c.Cancel) return; TabItem tabItem; // Using ItemsSource property if (ItemsSource != null) { IList list = (IList)ItemsSource; NewTabItemEventArgs n = new NewTabItemEventArgs(); if (NewTabItem == null) { //NewTabCommand.Execute(n); throw new InvalidOperationException("You must implement the NewTabItem event to supply the item to be added to the tab control."); } else { NewTabItem(this, n); if (n.Content == null) return; } if (i == -1 || i == list.Count - 1 || AddNewTabToEnd) list.Add(n.Content); else list.Insert(++i, n.Content); tabItem = (TabItem)this.ItemContainerGenerator.ContainerFromItem(n.Content); } else { // Using Items Property tabItem = new TabItem { Header = "New Tab" }; if (i == -1 || i == this.Items.Count - 1 || AddNewTabToEnd) this.Items.Add(tabItem); else this.Items.Insert(++i, tabItem); } if (TabItemAdded != null) TabItemAdded(this, new TabItemEventArgs(tabItem)); }