IHeaderDashboard.cs 1.7 KB

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