Reputation: 1071
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
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