DefaultDynamicEditorGridLayout.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. public override bool TabStripVisible
  13. {
  14. get { return Details.TabStripVisible; }
  15. set { Details.TabStripVisible = value; }
  16. }
  17. private DynamicTabControl Details;
  18. public DefaultDynamicEditorGridLayout()
  19. {
  20. Details = new DynamicTabControl();
  21. Details.VerticalAlignment = VerticalAlignment.Stretch;
  22. Details.HorizontalAlignment = HorizontalAlignment.Stretch;
  23. Details.Name = "Details";
  24. Details.SelectionChanged += Details_SelectionChanged;
  25. Content = Details;
  26. }
  27. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  28. {
  29. Details.Items.Clear();
  30. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  31. {
  32. var tab = new DynamicTabItem();
  33. tab.Header = page.Caption();
  34. tab.Content = page;
  35. Details.Items.Add(tab);
  36. }
  37. Details.SelectedItem = Details.Items.Count > 0 ? Details.Items[0] : null;
  38. }
  39. private bool bChanging;
  40. private void Details_SelectionChanged(object sender, SelectionChangedEventArgs e)
  41. {
  42. if (bChanging || Details?.SelectedItem == null || e.OriginalSource != Details)
  43. return;
  44. bChanging = true;
  45. try
  46. {
  47. var tab = Details.SelectedItem as DynamicTabItem;
  48. if (tab is not null && tab.Content is IDynamicEditorPage page)
  49. {
  50. SelectPage(page);
  51. }
  52. }
  53. finally
  54. {
  55. bChanging = false;
  56. }
  57. }
  58. }
  59. }