private void AddTabItem(string header, PlanListViewModel aPlanListViewModel) { if (string.IsNullOrEmpty(header) || null == aPlanListViewModel) { return; } var list = this.planListTabControl.Items.Where(w => ((TabItem)w).Header.ToString() == header); if (list.Count() > 0) { ((TabItem)list.First()).Visibility = Visibility.Visible; this.planListTabControl.SelectedItem = list.First(); } else { TabItem tabItem = new TabItem(); tabItem.Header = header; PlanListStatisticsDataGrid planListDataGrid = new PlanListStatisticsDataGrid(aPlanListViewModel, null != planExtraEntity); var tabContent = planListDataGrid as UserControl; tabItem.Content = tabContent; this.planListTabControl.Items.Add(tabItem); this.planListTabControl.SelectedItem = tabItem; } }