user2376998
user2376998

Reputation: 1071

WPF C# drag and drop passing values of startpoint

i have this piece of code here :

       public void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
    {
        // Get the current mouse position
        Point mousePos = e.GetPosition(null);

        Vector diff = startPoint - mousePos; // startPoint error

        if (e.LeftButton == MouseButtonState.Pressed &&
            Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
            Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
        {
            Label lbl = (Label)sender;
            DataObject dataObj = new DataObject(lbl.Content);
            DragDrop.DoDragDrop(lbl, dataObj, DragDropEffects.All);
        } 
    }

    public void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
       var startPoint = e.GetPosition(null);
    }

It says startPoint does not exist in previewmousemove , i am doing it in WPF , usually i save it into a session and pass it over but WPF doesn't have session , how do i solve this error? I am learning how to do drag and drop from http://wpftutorial.net/DragAndDrop.html and http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-wpf-explained-end-to-end.aspx

Upvotes: 0

Views: 367

Answers (1)

Tintenfiisch
Tintenfiisch

Reputation: 360

You can hangup to the PreviewMouseLeftButtonDown event and store the GetPosition Result in a private variable startpoint of your class.

private Point _startPoint;
yourTreeview_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    _startPoint = e.GetPosition(null);
}

Upvotes: 1

Related Questions