【发布时间】:2013-12-19 09:35:12
【问题描述】:
所以我在 WPF 中进行了一些拖放操作。使用 shift 键效果很好。
但是,如果我使用 ctrl 键开始拖动操作,dodraganddrop 方法运行良好。但是,当我按住 ctrl 键时,光标变为“不允许放置符号”,并且在放开控制键之前,我无法放置项目。为什么会这样,我该如何改变它?我认为光标是通过将 DragEventArgs.Effects 设置为 DragDropEffect 来确定的,但我已将其设置为 DragDropEffectsMove 并且仍然得到不允许放置的光标。
private void NameListView_MouseMove(object sender, MouseEventArgs e)
{
// Get the current mouse position
Point mousePos = e.GetPosition(null);
Vector diff = NameListViewMouseDownStartPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
)
{
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || Keyboard.IsKeyDown(Key.LeftCtrl)
|| Keyboard.IsKeyDown(Key.RightCtrl))
{
DataObject do1 = new DataObject("AddedItemsFormat", _GraphViewerViewModel.SelectedAddedItems);
DragDrop.DoDragDrop(NameListView, do1, DragDropEffects.Move);
}
}
}
private void NameListView_DragOver(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Move;
}
// Moves the item to the location of the insertion mark.
private void NameListView_DragDrop(object sender, DragEventArgs e)
{
//Drop Code. This code will not run unless the user first lets go of the control key so he can drop here
}
【问题讨论】:
标签: c# wpf drag-and-drop