コード例 #1
0
        public void MyOnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            //Console.WriteLine(string.Format("Left click on {0}, handled {1}.", this.Name, e.Handled));
            // super call
            base.OnPreviewMouseLeftButtonDown(e);

            // check if we clicked inside the color circle
            var clickPosition = e.GetPosition(colorCircle);
            var circleCenter = new Point(colorCircle.Width / 2, colorCircle.Height / 2);
            var circleRadius = colorCircle.Width / 2;
            var clickDistanceFromCenter = (clickPosition - circleCenter).Length;
            var nearEnough = clickDistanceFromCenter < circleRadius;

            if (!nearEnough)
                return;

            // save current values of rotation and scale
            var arrow = (Arrow)DataContext;
            var position = e.GetPosition(this);
            arrowDraggingData = new ArrowDraggingData(
                arrow.Angle, arrow.NormalizedLength,
                position,
                new Point(ActualWidth / 2, ActualHeight / 2));
            IsDragging = true;

            // tell the event has been handled
            e.Handled = true;
        }
コード例 #2
0
 private void stopDrag()
 {
     arrowDraggingData = null;
     IsDragging = false;
 }
コード例 #3
0
        public void MyOnPreviewMouseMove(MouseEventArgs e)
        {
            // super call
            base.OnPreviewMouseMove(e);

            // check if the mouse button is still down
            if (e.LeftButton == MouseButtonState.Released)
                stopDrag();

            // check if we are in a dragging operation
            if (arrowDraggingData == null)
                return;

            // compute data for the new position
            var newArrowDraggingData = new ArrowDraggingData(
                0, 0, // actually not used
                e.GetPosition(this), new Point(ActualWidth / 2, ActualHeight / 2));

            // compute the new angle
            var deltaAngle = newArrowDraggingData.ClickAngle - arrowDraggingData.ClickAngle;
            var newAngle = arrowDraggingData.StartingAngle + deltaAngle;

            // compute the new normalized length
            var deltaMouseNormalizedLength = newArrowDraggingData.ClickNormalizedLength - arrowDraggingData.ClickNormalizedLength;
            var newNormalizedLength = arrowDraggingData.StartingNormalizedLength + deltaMouseNormalizedLength;

            // apply changes to model
            var arrow = (Arrow)DataContext;
            arrow.Angle = newAngle;
            arrow.NormalizedLength = newNormalizedLength;

            // we handled the event
            e.Handled = true;
        }