VerticalDynamicEditorGridLayout.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
  16. namespace InABox.DynamicGrid
  17. {
  18. /// <summary>
  19. /// Interaction logic for VerticalDynamicEditorGridLayout.xaml
  20. /// </summary>
  21. public partial class VerticalDynamicEditorGridLayout : DynamicEditorGridLayout
  22. {
  23. public VerticalDynamicEditorGridLayout()
  24. {
  25. InitializeComponent();
  26. }
  27. public override void LoadPages(IEnumerable<IDynamicEditorPage> pages)
  28. {
  29. Editors.Items.Clear();
  30. OtherPages.Items.Clear();
  31. foreach (var page in pages.OrderBy(x => x.PageType).ThenBy(x => x.Order()).ThenBy(x => x.Caption()))
  32. {
  33. var tab = new DynamicTabItem();
  34. tab.Header = page.Caption();
  35. tab.Content = page;
  36. if(page is DynamicEditorGrid.DynamicEditPage)
  37. {
  38. Editors.Items.Add(tab);
  39. }
  40. else
  41. {
  42. OtherPages.Items.Add(tab);
  43. }
  44. }
  45. }
  46. private bool bChanging;
  47. private void Editors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  48. {
  49. if (bChanging) return;
  50. if ((e.OriginalSource != Editors && e.OriginalSource != OtherPages) || e.OriginalSource is not DynamicTabControl tabControl) return;
  51. if (tabControl.SelectedItem is not DynamicTabItem tab) return;
  52. bChanging = true;
  53. try
  54. {
  55. if (tab is not null && tab.Content is IDynamicEditorPage page)
  56. {
  57. SelectPage(page);
  58. }
  59. }
  60. finally
  61. {
  62. bChanging = false;
  63. }
  64. }
  65. }
  66. }