Пример #1
0
        private void OnOwnerMouseMove(object sender, MouseEventArgs e)
        {
            if (e.MouseDevice.LeftButton == MouseButtonState.Released)
            {
                FinishDrag();
                return;
            }

            Point point = e.GetPosition(Owner);

            if (!IsSelecting && SelectionBoxAdorner != null &&
                (System.Math.Abs(SelectionBoxAdorner.StartPoint.X - point.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 System.Math.Abs(SelectionBoxAdorner.StartPoint.Y - point.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                AdornerLayer parentAdorner = AdornerLayer.GetAdornerLayer(Owner);

                if (SelectionBoxAdorner != null)
                {
                    parentAdorner.Remove(SelectionBoxAdorner);
                }

                parentAdorner.Add(SelectionBoxAdorner);

                ElementManager.BeginSelection();
                IsSelecting = true;

                Owner.CaptureMouse();
            }

            if (SelectionBoxAdorner != null && IsSelecting)
            {
                SelectionBoxAdorner.EndPoint = point;
                SelectionBoxAdorner.InvalidateVisual();

                ElementManager.UpdateSelection(new Rect(SelectionBoxAdorner.StartPoint, SelectionBoxAdorner.EndPoint));
            }

            e.Handled = true;
        }