/// <summary> /// Creates a new tab, or returns the existing tab for the group /// </summary> /// <param name="group">The group.</param> /// <param name="groupName">Name of the group.</param> /// <returns>TabItem.</returns> private TabItem GetNewOrExistingGroupTab(IList <ViewResult> group, string groupName) { var tab = Items.OfType <TabItem>().FirstOrDefault(t => GetAssociatedGroupName(t) == groupName); if (tab != null) { SelectedItem = tab; return(tab); } var newTab = new TabItem(); SetAssociatedGroupName(newTab, groupName); var backgroundColor = SimpleView.GetViewThemeColor(group[0].View); if (backgroundColor != Colors.Transparent) { newTab.Background = new SolidColorBrush(backgroundColor); } var foregroundBrush = SimpleView.GetTitleColor(group[0].View); if (foregroundBrush != null) { newTab.Foreground = foregroundBrush; } newTab.DataContext = group; // We assign the whole collection here so we can reference to it later var subTabs = new TabControl(); if (SubTabControlStyle != null) { subTabs.Style = SubTabControlStyle; } newTab.Content = subTabs; Items.Add(newTab); SelectedItem = newTab; return(newTab); }