3
在我們的應用程序,我們舉辦一個小WPF列表框的元素主機內,我們實施的阻力和使用PreviewMouseDown事件下降...如何實現從Winforms應用程序中的小型WPF元素主機的拖放操作?
private void Border_PreviewMouseMove(object sender, MouseEventArgs e)
{
// Get the current mouse position
Point mousePos = e.GetPosition(null);
Vector diff = startPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed &&
Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
{
OnDragStarted(e);
}
}
我們所看到的問題是,當我點擊並拖動項目很快,WPF控件在鼠標離開Elementhost之前僅觸發一個PreviewMouseMove事件,因此拖動操作不會啓動,直到鼠標返回到Elementhost並引發另一個PreviewMouseMove事件。
有處理這種情況的強大方法嗎?
謝謝!這個問題一直困擾着我的應用很長一段時間,現在它終於得到修復。我在預覽鼠標向下事件中調用Child.CaptureMouse(),在預覽鼠標向上事件中調用Child.ReleaseMouseCapture()。 – Andy 2013-04-11 09:04:35