VerticalDynamicEditorGridLayout.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. tab.Content = page;
  40. if(page is DynamicEditorGrid.DynamicEditPage)
  41. {
  42. Editors.Items.Add(tab);
  43. }
  44. else
  45. {
  46. OtherPages.Items.Add(tab);
  47. }
  48. }
  49. Editors.SelectedIndex = 0;
  50. }
  51. private bool bChanging;
  52. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  53. {
  54. if (bChanging) return;
  55. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  56. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  57. bChanging = true;
  58. try
  59. {
  60. if (tab is not null && tab.Content is IDynamicEditorPage page)
  61. {
  62. SelectPage(page);
  63. }
  64. }
  65. finally
  66. {
  67. bChanging = false;
  68. }
  69. }
  70. }
  71. }