| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using MuchInfo.Chart.Infrastructure.Helpers;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace MuchInfo.Chart.WPF.Controls.Utilities
- {
- /// <summary>
- /// MainMenuButton.xaml 的交互逻辑
- /// </summary>
- public partial class MainMenuButton : UserControl
- {
- #region Fields
- private bool _isMouseEnter;
- private bool _isPopuOpen;
- private PopupMenu _popupMenu;
- #endregion Fields
- #region Constructors
- public MainMenuButton()
- {
- this._isMouseEnter = false;
- this._isPopuOpen = false;
- this.InitializeComponent();
- }
- #endregion Constructors
- #region Delegates
- public delegate void FillTheMenuEventHandler(PopupMenu aMenu);
- #endregion Delegates
- #region Events
- public event MainMenuButton.FillTheMenuEventHandler FillTheMenu;
- #endregion Events
- #region Properties
- #region Public Properties
- public virtual PopupMenu PopupMenu
- {
- get
- {
- return this._popupMenu;
- }
- set
- {
- var obj = new PopupMenu.PopupClosedEventHandler(this.OnPopup_Closed);
- bool flag = this._popupMenu != null;
- if (flag)
- {
- this._popupMenu.PopupClosed -= obj;
- }
- this._popupMenu = value;
- flag = (this._popupMenu != null);
- if (flag)
- {
- this._popupMenu.PopupClosed += obj;
- }
- }
- }
- public string Text
- {
- get
- {
- return this.lblMain.Text;
- }
- set
- {
- this.lblMain.Text = value;
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Protected Methods
- protected virtual void OnFillTheMenu(PopupMenu amenu)
- {
- var handler = FillTheMenu;
- if (handler != null) handler(amenu);
- }
- #endregion Protected Methods
- #region Private Methods
- private void LayoutRoot_MouseEnter(object sender, MouseEventArgs e)
- {
- this._isMouseEnter = true;
- this.SetBorderHover();
- bool flag = PopupMenu.MenuIsUp();
- if (flag)
- {
- this.ShowMenu();
- }
- }
- private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
- {
- this._isMouseEnter = false;
- this.SetBorderHover();
- }
- private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- this.ShowMenu();
- }
- private void OnPopup_Closed()
- {
- this.PopupMenu = null;
- this._isPopuOpen = false;
- this.SetBorderHover();
- }
- private void SetBorderHover()
- {
- if (this._isMouseEnter || this._isPopuOpen)
- {
- this.borderHover.Background = new LinearGradientBrush()
- {
- GradientStops = new GradientStopCollection()
- {
- new GradientStop {Color = ColorHelper.LightBlue, Offset = 0.0},
- new GradientStop {Color = ColorHelper.SteelBlue, Offset = 1.0}
- }
- };
- this.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 34, 34, 34));
- }
- else
- {
- this.borderHover.Background = new SolidColorBrush(Colors.Transparent);
- this.borderHover.BorderBrush = null;
- }
- }
- private void ShowMenu()
- {
- //if (this.PopupMenu != null)
- //{
- // this.PopupMenu.ClosePopup();
- // this.PopupMenu = null;
- //}
- //this.PopupMenu = new PopupMenu();
- //OnFillTheMenu(this.PopupMenu);
- //this._isPopuOpen = true;
- //this.PopupMenu.ShowMainMenu(this);
- //this.SetBorderHover();
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|