using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace InABox.DynamicGrid { public class DefaultDynamicEditorGridLayout : DynamicEditorGridLayout { private DynamicTabControl Details; public DefaultDynamicEditorGridLayout() { Details = new DynamicTabControl(); Details.VerticalAlignment = VerticalAlignment.Stretch; Details.HorizontalAlignment = HorizontalAlignment.Stretch; Details.Name = "Details"; Details.SelectionChanged += Details_SelectionChanged; Content = Details; } public override void LoadPages(IEnumerable pages) { Details.Items.Clear(); foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption())) { var tab = new DynamicTabItem(); tab.Header = page.Caption(); tab.Content = page; Details.Items.Add(tab); } } private bool bChanging; private void Details_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (bChanging || Details?.SelectedItem == null || e.OriginalSource != Details) return; bChanging = true; try { var tab = Details.SelectedItem as DynamicTabItem; if (tab is not null && tab.Content is IDynamicEditorPage page) { SelectPage(page); } } finally { bChanging = false; } } } }