我一直在开发一个WPF应用程序,它本质上是一个所见即所得的编辑器,并使用拖放功能。我已经实现了拖放功能,但需要使其更加直观和用户友好。其中一部分涉及实际显示正在拖动的项目。最简单的方法是什么?我拖动的项目并不是特别特殊,但我甚至不确定在哪里查找如何做到这一点。
我一直在开发一个WPF应用程序,它本质上是一个所见即所得的编辑器,并使用拖放功能。我已经实现了拖放功能,但需要使其更加直观和用户友好。其中一部分涉及实际显示正在拖动的项目。最简单的方法是什么?我拖动的项目并不是特别特殊,但我甚至不确定在哪里查找如何做到这一点。
你需要利用DragDrop.GiveFeedback等其他技术。
以下是一个旧博客文章中处理光标操作的简单示例...
private void StartDragCustomCursor(MouseEventArgs e)
{
GiveFeedbackEventHandler handler = new GiveFeedbackEventHandler(DragSource_GiveFeedback);
this.DragSource.GiveFeedback += handler;
IsDragging = true;
DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), "abcd");
DragDropEffects de = DragDrop.DoDragDrop(this.DragSource, data, DragDropEffects.Move);
this.DragSource.GiveFeedback -= handler;
IsDragging = false;
}
void DragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
try
{
//This loads the cursor from a stream ..
if (_allOpsCursor == null)
{
using (Stream cursorStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
"SimplestDragDrop.DDIcon.cur"))
{
_allOpsCursor = new Cursor(cursorStream);
}
}
Mouse.SetCursor(_allOpsCursor);
e.UseDefaultCursors = false;
e.Handled = true;
}
finally { }
}