MainMenuButton.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using MuchInfo.Chart.Infrastructure.Helpers;
  2. using System.Windows.Controls;
  3. using System.Windows.Input;
  4. using System.Windows.Media;
  5. namespace MuchInfo.Chart.WPF.Controls.Utilities
  6. {
  7. /// <summary>
  8. /// MainMenuButton.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class MainMenuButton : UserControl
  11. {
  12. #region Fields
  13. private bool _isMouseEnter;
  14. private bool _isPopuOpen;
  15. private PopupMenu _popupMenu;
  16. #endregion Fields
  17. #region Constructors
  18. public MainMenuButton()
  19. {
  20. this._isMouseEnter = false;
  21. this._isPopuOpen = false;
  22. this.InitializeComponent();
  23. }
  24. #endregion Constructors
  25. #region Delegates
  26. public delegate void FillTheMenuEventHandler(PopupMenu aMenu);
  27. #endregion Delegates
  28. #region Events
  29. public event MainMenuButton.FillTheMenuEventHandler FillTheMenu;
  30. #endregion Events
  31. #region Properties
  32. #region Public Properties
  33. public virtual PopupMenu PopupMenu
  34. {
  35. get
  36. {
  37. return this._popupMenu;
  38. }
  39. set
  40. {
  41. var obj = new PopupMenu.PopupClosedEventHandler(this.OnPopup_Closed);
  42. bool flag = this._popupMenu != null;
  43. if (flag)
  44. {
  45. this._popupMenu.PopupClosed -= obj;
  46. }
  47. this._popupMenu = value;
  48. flag = (this._popupMenu != null);
  49. if (flag)
  50. {
  51. this._popupMenu.PopupClosed += obj;
  52. }
  53. }
  54. }
  55. public string Text
  56. {
  57. get
  58. {
  59. return this.lblMain.Text;
  60. }
  61. set
  62. {
  63. this.lblMain.Text = value;
  64. }
  65. }
  66. #endregion Public Properties
  67. #endregion Properties
  68. #region Methods
  69. #region Protected Methods
  70. protected virtual void OnFillTheMenu(PopupMenu amenu)
  71. {
  72. var handler = FillTheMenu;
  73. if (handler != null) handler(amenu);
  74. }
  75. #endregion Protected Methods
  76. #region Private Methods
  77. private void LayoutRoot_MouseEnter(object sender, MouseEventArgs e)
  78. {
  79. this._isMouseEnter = true;
  80. this.SetBorderHover();
  81. bool flag = PopupMenu.MenuIsUp();
  82. if (flag)
  83. {
  84. this.ShowMenu();
  85. }
  86. }
  87. private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
  88. {
  89. this._isMouseEnter = false;
  90. this.SetBorderHover();
  91. }
  92. private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  93. {
  94. this.ShowMenu();
  95. }
  96. private void OnPopup_Closed()
  97. {
  98. this.PopupMenu = null;
  99. this._isPopuOpen = false;
  100. this.SetBorderHover();
  101. }
  102. private void SetBorderHover()
  103. {
  104. if (this._isMouseEnter || this._isPopuOpen)
  105. {
  106. this.borderHover.Background = new LinearGradientBrush()
  107. {
  108. GradientStops = new GradientStopCollection()
  109. {
  110. new GradientStop {Color = ColorHelper.LightBlue, Offset = 0.0},
  111. new GradientStop {Color = ColorHelper.SteelBlue, Offset = 1.0}
  112. }
  113. };
  114. this.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 34, 34, 34));
  115. }
  116. else
  117. {
  118. this.borderHover.Background = new SolidColorBrush(Colors.Transparent);
  119. this.borderHover.BorderBrush = null;
  120. }
  121. }
  122. private void ShowMenu()
  123. {
  124. //if (this.PopupMenu != null)
  125. //{
  126. // this.PopupMenu.ClosePopup();
  127. // this.PopupMenu = null;
  128. //}
  129. //this.PopupMenu = new PopupMenu();
  130. //OnFillTheMenu(this.PopupMenu);
  131. //this._isPopuOpen = true;
  132. //this.PopupMenu.ShowMainMenu(this);
  133. //this.SetBorderHover();
  134. }
  135. #endregion Private Methods
  136. #endregion Methods
  137. }
  138. }