public void NewButtonClicked(object parameter) { TabControlExt tabControl = parameter as TabControlExt; int count = tabControl.Items.Count + 1; TabItem_ViewModel new_model1 = new TabItem_ViewModel() { Header = "tabItem" + count, Content = "This is the content of " + count + " tabitem." }; tabItems.Add(new_model1); }
protected override void OnAttached() { AssociatedObject.Loaded += (sender, e) => { TimeConsumingView control = sender as TimeConsumingView; TabControlExt tabcontrol = VisualUtils.FindAncestor(control as Visual, typeof(TabControlExt)) as TabControlExt; if (tabcontrol != null) { int index = tabcontrol.Items.IndexOf(control); if (index > -1 && index < tabcontrol.Items.Count && index == 0) { for (int i = 0; i < tabcontrol.Items.Count; i++) { TabItemExt item = tabcontrol.ItemContainerGenerator.ContainerFromIndex(i) as TabItemExt; if (item != null) { switch (i) { case 0: item.Header = "2006-2007"; break; case 1: item.Header = "2007-2008"; break; case 2: item.Header = "2008-2009"; break; case 3: item.Header = "2009-2010"; break; case 4: item.Header = "2010-2011"; break; case 5: item.Header = "2011-2012"; break; default: break; } } } } } if (!DesignerProperties.GetIsInDesignMode(new DependencyObject())) { DemoBrowserViewModel samplecontrol = null; if ((System.Windows.Application.Current.MainWindow.DataContext is DemoBrowserViewModel)) { samplecontrol = (System.Windows.Application.Current.MainWindow.DataContext as DemoBrowserViewModel); } if (control.reload.IsChecked.Value) { samplecontrol.IsProductDemoBusy = true; Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { control.Chart1.DataContext = new TestingViewModel(); control.Chart2.DataContext = new ChartViewModel(); samplecontrol.IsProductDemoBusy = false; isloaded = true; })); } else { if (!isloaded) { samplecontrol.IsProductDemoBusy = true; Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { control.Chart1.DataContext = new TestingViewModel(); control.Chart2.DataContext = new ChartViewModel(); samplecontrol.IsProductDemoBusy = false; isloaded = true; })); } } } }; }