VerticalDynamicEditorGridLayout.xaml.cs 3.1 KB

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