IHeaderDashboard.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using PRS.Shared;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. namespace PRSDesktop
  10. {
  11. public delegate void HeaderChangedEvent(DashboardHeader header);
  12. public class DashboardHeader
  13. {
  14. private readonly List<FrameworkElement> LeftElements = new();
  15. private readonly List<FrameworkElement> RightElements = new();
  16. private bool Updating = false;
  17. public event HeaderChangedEvent? HeaderChanged;
  18. public DashboardHeader BeginUpdate()
  19. {
  20. Updating = true;
  21. return this;
  22. }
  23. public DashboardHeader EndUpdate()
  24. {
  25. Updating = false;
  26. Update();
  27. return this;
  28. }
  29. private void Update()
  30. {
  31. if (!Updating)
  32. {
  33. HeaderChanged?.Invoke(this);
  34. }
  35. }
  36. public DashboardHeader Clear()
  37. {
  38. LeftElements.Clear();
  39. RightElements.Clear();
  40. Update();
  41. return this;
  42. }
  43. public DashboardHeader Add(FrameworkElement element)
  44. {
  45. LeftElements.Add(element);
  46. Update();
  47. return this;
  48. }
  49. public DashboardHeader AddRight(FrameworkElement element)
  50. {
  51. RightElements.Add(element);
  52. Update();
  53. return this;
  54. }
  55. public IEnumerable<FrameworkElement> GetLeftElements() => LeftElements;
  56. public IEnumerable<FrameworkElement> GetRightElements() => RightElements;
  57. }
  58. public interface IHeaderDashboard
  59. {
  60. DashboardHeader Header { get; }
  61. }
  62. }