using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace MuchInfo.Chart.WPF.Controls.Utilities { /// /// ChartMenuItem.xaml 的交互逻辑 /// public partial class ChartMenuItem : UserControl { #region Fields public object theItem; private bool _isMouseDown; private EventHandler _onClick; private PopupMenu _popupMenu; #endregion Fields #region Constructors public ChartMenuItem(string txt, EventHandler onClick) : this(txt, null, onClick) { } public ChartMenuItem(string txt, ImageSource image, EventHandler onClick) { base.MouseEnter -= this.ChartMenuItem_MouseEnter; base.MouseLeave -= this.ChartMenuItem_MouseLeave; base.MouseLeftButtonDown -= this.ChartMenuItem_MouseLeftButtonDown; base.MouseLeftButtonUp -= this.ChartMenuItem_MouseLeftButtonUp; base.MouseEnter += this.ChartMenuItem_MouseEnter; base.MouseLeave += this.ChartMenuItem_MouseLeave; base.MouseLeftButtonDown += this.ChartMenuItem_MouseLeftButtonDown; base.MouseLeftButtonUp += this.ChartMenuItem_MouseLeftButtonUp; this._isMouseDown = false; this.InitializeComponent(); this.lblMenu.Text = (txt); this._onClick = onClick; if (image != null) { this.imgMenu.Source = image; this.imgMenu.Width = 16.0; this.imgMenu.Height = 16.0; } } #endregion Constructors #region Methods #region Internal Methods internal void HideHover() { this.Hover.Visibility = Visibility.Collapsed; } internal void SetPopupMenu(PopupMenu aPop) { this._popupMenu = aPop; } #endregion Internal Methods #region Private Methods private void ChartMenuItem_MouseEnter(object sender, MouseEventArgs e) { bool flag = this.ActualWidth.Equals(0) || this.ActualHeight.Equals(0); if (!flag && this._onClick != null) { this.Hover.Visibility = Visibility.Visible; } } private void ChartMenuItem_MouseLeave(object sender, MouseEventArgs e) { this.Hover.Visibility = Visibility.Collapsed; } private void ChartMenuItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this._isMouseDown = true; } private void ChartMenuItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_isMouseDown) { if (this._onClick != null) { this._onClick.Invoke(this, e); } this._popupMenu.ClosePopup(); } this._isMouseDown = false; } #endregion Private Methods #endregion Methods } }