快速拖动矩形对象时,拖动停止

时间:2018-11-25 10:08:53

标签: c# .net wpf drag-and-drop wpf-controls

快速拖动矩形对象时,拖动停止并且光标仅移动。在不释放按钮单击按钮的情况下,在矩形对象上移动光标会再次开始拖动。当我以恒定速度拖动时,拖动效果很好。

我的代码是

    private void ConnectorMethod()
    {
     _draggedLine = new Rectangle();
     _draggedLine.Width = 100;
     _draggedLine.Height = 12;
     _controlModel.PlayerCanvas.Children.Add(_draggedLine);
     _draggedLine.PreviewMouseLeftButtonDown += copy_Connector;
     _draggedLine.PreviewMouseLeftButtonUp += connector_leftUp;
    }

    private void copy_Connector(object sender, MouseButtonEventArgs e)
    {
        _connecting_Connector = (Rectangle)sender;
        _Connector_position = e.GetPosition(_connecting_Connector);
        _connecting_Connector.PreviewMouseMove += ConnectorMouseMove;

    }

    private void connector_leftUp(object sender, MouseButtonEventArgs e)
    {
        _connecting_Connector.PreviewMouseMove -= ConnectorMouseMove;
    }

    private void ConnectorMouseMove(object sender, MouseEventArgs e)
    {

        if (e.LeftButton == MouseButtonState.Pressed)
        {
            Point canvasRelativePosition = e.GetPosition(_controlModel.PlayerCanvas);
            Canvas.SetTop(_connecting_Connector, canvasRelativePosition.Y - _Connector_position.Y);
            Canvas.SetLeft(_connecting_Connector, canvasRelativePosition.X - _Connector_position.X);
            e.Handled = true;
        }
    }

谢谢。

1 个答案:

答案 0 :(得分:0)

我已通过

中的实现画布矩形对象修复了它