DefaultDynamicEditorGridLayout.cs 2.0 KB

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