VerticalDynamicEditorGridLayout.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 VerticalDynamicEditorGridLayout()
  23. {
  24. InitializeComponent();
  25. }
  26. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  27. {
  28. Editors.Items.Clear();
  29. OtherPages.Items.Clear();
  30. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  31. {
  32. var tab = new DynamicTabItem();
  33. tab.Header = page.Caption();
  34. tab.Content = page;
  35. if(page is DynamicEditorGrid.DynamicEditPage)
  36. {
  37. Editors.Items.Add(tab);
  38. }
  39. else
  40. {
  41. OtherPages.Items.Add(tab);
  42. }
  43. }
  44. }
  45. private bool bChanging;
  46. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  47. {
  48. if (bChanging) return;
  49. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  50. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  51. bChanging = true;
  52. try
  53. {
  54. if (tab is not null && tab.Content is IDynamicEditorPage page)
  55. {
  56. SelectPage(page);
  57. }
  58. }
  59. finally
  60. {
  61. bChanging = false;
  62. }
  63. }
  64. }
  65. }