【发布时间】:2013-10-15 21:09:59
【问题描述】:
我正在处理一个 Wpf 项目,但现在我遇到了 ListView 问题。
事实证明,我在 ListView 上实现了 Drag&Drop 功能,效果很好。当我尝试向下或向上滚动时,问题就来了。通过这样做,Drag&Drop 功能被激活,阻止我继续滚动。
我找到了this solution,这表明我们需要将控件附加到ScrollChanged 事件。
<ListView ScrollViewer.ScrollChanged="listView1_ScrollChanged"...
但我真的不知道在那个处理程序中该做什么。 如何禁用该事件的拖放功能?我怎样才能再次启用它?或者,有没有更好的方法来解决这个问题?
这是我的Drag&Drop代码:
private void listView1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Store the mouse position
startPoint = e.GetPosition(null);
}
private void listView1_MouseMove(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))
{
// Get the dragged ListViewItem
ListView listView = sender as ListView;
// Get items to drag
var a = listView.SelectedItems;
// Initialize the drag & drop operation
DataObject dragData = new DataObject("myFormat", a);
DragDrop.DoDragDrop(listView, dragData, DragDropEffects.Move);
}
}
提前致谢。
【问题讨论】:
-
也许你能告诉我们你是如何实现拖放功能的......
-
@Georgi-it 添加代码
标签: c# wpf listview drag-and-drop scroll