DefaultDynamicEditorGridLayout.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace InABox.DynamicGrid
  9. {
  10. public class DefaultDynamicEditorGridLayout : DynamicEditorGridLayout
  11. {
  12. private DynamicTabControl Details;
  13. public DefaultDynamicEditorGridLayout()
  14. {
  15. Details = new DynamicTabControl();
  16. Details.VerticalAlignment = VerticalAlignment.Stretch;
  17. Details.HorizontalAlignment = HorizontalAlignment.Stretch;
  18. Details.Name = "Details";
  19. Details.SelectionChanged += Details_SelectionChanged;
  20. Content = Details;
  21. }
  22. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  23. {
  24. Details.Items.Clear();
  25. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  26. {
  27. var tab = new DynamicTabItem();
  28. tab.Header = page.Caption();
  29. tab.Content = page;
  30. Details.Items.Add(tab);
  31. }
  32. }
  33. private bool bChanging;
  34. private void Details_SelectionChanged(object sender, SelectionChangedEventArgs e)
  35. {
  36. if (bChanging || Details?.SelectedItem == null || e.OriginalSource != Details)
  37. return;
  38. bChanging = true;
  39. try
  40. {
  41. var tab = Details.SelectedItem as DynamicTabItem;
  42. if (tab is not null && tab.Content is IDynamicEditorPage page)
  43. {
  44. SelectPage(page);
  45. }
  46. }
  47. finally
  48. {
  49. bChanging = false;
  50. }
  51. }
  52. }
  53. }