我在这里有这段代码:
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);
}
它说 startPoint 在 previewmousemove 中不存在,我在 WPF 中执行此操作,通常我将其保存到会话中并将其传递但 WPF 没有会话,我该如何解决此错误?我正在学习如何从http://wpftutorial.net/DragAndDrop.html和http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-进行拖放wpf-explained-end-to-end.aspx