private void AddTabItem(dhAccount objTodisplay) { // create new tab AccountIn TabItem tab = new TabItem(); string tabName = ""; if (objTodisplay.AccountName != null) { tabName = "Account No - ' " + objTodisplay.VAccountNo + " '"; } else { tabName = "Add New Account"; } tab.Header = string.Format(tabName); tab.Name = string.Format("Account{0}", tabDynamic.Items.Count + 1); tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate; // tab.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick); AddAccountView wintoOpen = new AddAccountView(objTodisplay); tab.Content = wintoOpen; tab.IsSelected = true; //var AccountIn = tabDynamic.Items.Cast<TabItem>().Where(i => i.Name.Equals(tab.Name)).SingleOrDefault(); //if (AccountIn == null) //{ if (tabDynamic.Items.Count > 1) { tabDynamic.Items.Insert(tabDynamic.Items.Count - 1, tab); // inset the Eid tab } else { tabDynamic.Items.Insert(tabDynamic.Items.Count, tab); // inset the Eid tab } //} //else //{ // AccountIn.IsSelected = true; //} // tabDynamic.DataContext = _TabItems; }
private void tabAdd_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TabItem tab = tabDynamic.SelectedItem as TabItem; TabItem _tabAdd = tabDynamic.Items[0] as TabItem; if (tab == null) { return; } if ((tab.Header.Equals(" + ")) && (tabDynamic.Items.Count > 1)) { TabItem Newtabs = new TabItem(); string tabName = ""; dhAccount Obj = new dhAccount(); // AddTabItem(Obj); tabName = "Add New Account"; Newtabs.Header = string.Format(tabName); Newtabs.Name = string.Format("AddAccountView"); Newtabs.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate; // Newtabs.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick); AddAccountView wintoOpen = new AddAccountView(); Newtabs.Content = wintoOpen; Newtabs.IsSelected = true; var Account = tabDynamic.Items.Cast <TabItem>().Where(i => i.Name.Equals(Newtabs.Name)).SingleOrDefault(); if (Account == null) { tabDynamic.Items.Insert(tabDynamic.Items.Count - 1, Newtabs); } else { Account.IsSelected = true; } } else { tab.IsSelected = true; } }