VerticalDynamicEditorGridLayout.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace InABox.DynamicGrid;
  16. /// <summary>
  17. /// Interaction logic for VerticalDynamicEditorGridLayout.xaml
  18. /// </summary>
  19. public partial class VerticalDynamicEditorGridLayout : DynamicEditorGridLayout
  20. {
  21. public override bool TabStripVisible
  22. {
  23. get { return Editors.TabStripVisible; }
  24. set { Editors.TabStripVisible = value; }
  25. }
  26. private double _totalWidth;
  27. public override double TotalWidth => _totalWidth;
  28. private double _editorHeight;
  29. private double _pageHeight;
  30. public override double TotalHeight => _editorHeight + _pageHeight;
  31. public VerticalDynamicEditorGridLayout()
  32. {
  33. InitializeComponent();
  34. }
  35. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  36. {
  37. Editors.Items.Clear();
  38. OtherPages.Items.Clear();
  39. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order).ThenBy(x => x.Caption()))
  40. {
  41. var tab = new DynamicTabItem();
  42. tab.Header = page.Caption();
  43. if (page is FrameworkElement element)
  44. element.Margin = new Thickness(0, 2, 0, 0);
  45. tab.Content = page;
  46. var minSize = page.MinimumSize();
  47. if(page is DynamicEditorGrid.DynamicEditPage)
  48. {
  49. Editors.Items.Add(tab);
  50. _editorHeight = Math.Max(_editorHeight, minSize.Height);
  51. _totalWidth = Math.Max(_totalWidth, minSize.Width);
  52. }
  53. else
  54. {
  55. OtherPages.Items.Add(tab);
  56. _pageHeight = Math.Max(_pageHeight, minSize.Height);
  57. }
  58. }
  59. Editors.SelectedIndex = 0;
  60. }
  61. private bool bChanging;
  62. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  63. {
  64. if (bChanging) return;
  65. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  66. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  67. bChanging = true;
  68. try
  69. {
  70. if (tab is not null && tab.Content is IDynamicEditorPage page)
  71. {
  72. SelectPage(page);
  73. }
  74. }
  75. finally
  76. {
  77. bChanging = false;
  78. }
  79. }
  80. private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
  81. {
  82. EditorRow.MaxHeight = e.NewSize.Height - 50;
  83. }
  84. }