using MuchInfo.Chart.Infrastructure.Helpers; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace MuchInfo.Chart.WPF.Controls.Utilities { /// /// MainMenuButton.xaml 的交互逻辑 /// 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 } }