VerticalDynamicEditorGridLayout.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. public VerticalDynamicEditorGridLayout()
  28. {
  29. InitializeComponent();
  30. }
  31. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  32. {
  33. Editors.Items.Clear();
  34. OtherPages.Items.Clear();
  35. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  36. {
  37. var tab = new DynamicTabItem();
  38. tab.Header = page.Caption();
  39. if (page is FrameworkElement element)
  40. element.Margin = new Thickness(0, 2, 0, 0);
  41. tab.Content = page;
  42. if(page is DynamicEditorGrid.DynamicEditPage)
  43. {
  44. Editors.Items.Add(tab);
  45. }
  46. else
  47. {
  48. OtherPages.Items.Add(tab);
  49. }
  50. }
  51. Editors.SelectedIndex = 0;
  52. }
  53. private bool bChanging;
  54. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  55. {
  56. if (bChanging) return;
  57. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  58. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  59. bChanging = true;
  60. try
  61. {
  62. if (tab is not null && tab.Content is IDynamicEditorPage page)
  63. {
  64. SelectPage(page);
  65. }
  66. }
  67. finally
  68. {
  69. bChanging = false;
  70. }
  71. }
  72. private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
  73. {
  74. EditorRow.MaxHeight = e.NewSize.Height - 50;
  75. }
  76. }
  77. }