VerticalDynamicEditorGridLayout.xaml.cs 2.5 KB

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