示例#1
0
        /// <summary>
        /// Invoked when an unhandled <see cref="E:System.Windows.UIElement.MouseLeftButtonDown" /> routed event is raised on this element. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the left mouse button was pressed.</param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            _lastMouseDownHotArea = null;

            base.OnMouseLeftButtonDown(e);

            var mousePosition = e.GetPosition(this);
            if (mousePosition.X < 0d || mousePosition.Y < 0d || mousePosition.X > Width || mousePosition.Y > Height) return;

            foreach (var hotArea in _hotAreas)
                if (hotArea.AreaRectangle.Contains(mousePosition))
                {
                    _lastMouseDownHotArea = hotArea;
                    if (hotArea.MouseDown != null)
                    {
                        hotArea.MouseDown(this, e);
                        if (e.Handled)
                        {
                            _lastMouseDownHotArea = null;
                            break;
                        }
                    }
                }
        }
示例#2
0
 /// <summary>Adds a hot area to the overall list</summary>
 /// <param name="hotArea">The hot area.</param>
 public void AddHotArea(HotArea hotArea)
 {
     _hotAreas.Add(hotArea);
 }