コード例 #1
0
        private void root_MouseMove(object sender, MouseEventArgs e)
        {
            var element = sender as FrameworkElement;

            if (element != null && (CurrentElement == null && (bool)element.GetValue(EditModeAttachedProperty)))
            {
                ShowArrows(element);
            }

            if (!ValidateElement(element))
            {
                return;
            }


            if (_transformX || _transformY)
            {
                var minHeight = RowDefinitions.Min(rd => rd.ActualHeight);
                var minLength = ColumnDefinitions.Min(rd => rd.ActualWidth);


                var mouseDelta = Mouse.GetPosition(this);
                mouseDelta.Offset(-_mouseOffset.X, -_mouseOffset.Y);

                if (CurrentElement != null)
                {
                    var scaleY = 1 +
                                 (Math.Abs(_renderOriginY - 1.0) < double.Epsilon ? -1 : 1) * mouseDelta.Y /
                                 CurrentElement.RenderSize.Height;
                    var scaleX = 1 +
                                 (Math.Abs(_renderOriginX - 1.0) < double.Epsilon ? -1 : 1) * mouseDelta.X /
                                 CurrentElement.RenderSize.Width;

                    if (RenderSize.Height * scaleY <= minHeight || RenderSize.Width * scaleX <= minLength)
                    {
                        UnsafeMethods.SetCursorPos(_prevPosition.X, _prevPosition.Y);
                        return;
                    }

                    var scale = ((TransformGroup)CurrentElement.RenderTransform).Children.OfType <ScaleTransform>().First();
                    CurrentElement.RenderTransformOrigin = new Point(_renderOriginX, _renderOriginY);
                    if (_transformY)
                    {
                        scale.ScaleY = scaleY;
                    }

                    if (_transformX)
                    {
                        scale.ScaleX = scaleX; // < 1 ? 1.0 : scaleX;
                    }
                }
            }
            else
            {
                var mouseDelta = Mouse.GetPosition(this);
                mouseDelta.Offset(-_mouseOffset.X, -_mouseOffset.Y);

                if (element != null)
                {
                    element.Margin = new Thickness(
                        Margin.Left + mouseDelta.X,
                        Margin.Top + mouseDelta.Y,
                        Margin.Right - mouseDelta.X,
                        Margin.Bottom - mouseDelta.Y);
                }
            }

            UnsafeMethods.GetCursorPos(ref _prevPosition);


            int col;
            int row;

            GetPosition(out col, out row);


            //  notify about all movements
            if (ControlChanging != null)
            {
                var newState = GetCurrentControlState(element, col, row);
                OnControlChanging(newState, CheckCollisions(newState));
            }
            e.Handled = true;
        }