/// <summary> /// Handle the mouse left button up event. Here we actually process the selected rectangle /// if any by first raising an event for client to receive then also zooming to that rectangle /// if ZoomSelection is true /// </summary> /// <param name="sender">Mouse</param> /// <param name="e">Mouse button information</param> void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { _watching = false; if (_selectionRectVisual != null) { Mouse.Capture(_target, CaptureMode.None); Point pos = e.GetPosition(_container); double f = Math.Min(Math.Abs(pos.X - _mouseDownPoint.X), Math.Abs(pos.Y - _mouseDownPoint.Y)); Rect r = GetSelectionRect(pos); _selectionRect = r; if (Selected != null) { Selected(this, EventArgs.Empty); } // if (_fszoomSelection && f > _fszoomSizeThreshold) // ÏÞÖÆËõ·Å±ÈÀý if (_fszoomSelection && f > _fszoomSizeThreshold && _fszoom.Zoom <= 1) { _fszoom.ZoomToRect(r); } _container.Children.Remove(_selectionRectVisual); _selectionRectVisual = null; } }
/// <summary> /// Handle Mouse Move event. Here we detect whether we've exceeded the _selectionThreshold /// and if so capture the mouse and create the visual zoom rectangle on the container object. /// </summary> /// <param name="sender">Mouse</param> /// <param name="e">Mouse move information.</param> void OnMouseMove(object sender, MouseEventArgs e) { if (_watching) { Point pos = e.GetPosition(_container); if (new Vector(_start.X - pos.X, _start.Y - pos.Y).Length > _selectionThreshold) { _watching = false; Mouse.Capture(_target, CaptureMode.SubTree); _selectionRectVisual = new SelectionRectVisual(_start, _start, _fszoom.Zoom); _container.Children.Add(_selectionRectVisual); } } if (_selectionRectVisual != null) { if (_selectionRectVisual.Zoom != _fszoom.Zoom) { _selectionRectVisual.Zoom = _fszoom.Zoom; } _selectionRectVisual.SecondPoint = e.GetPosition(_container); } }