I have been working on a WPF Application that is essentially a WYSIWYG editor, and is using drag and drop functionality. I have the drag and drop functionality working, but need to make it more intuitive and user friendly. Part of this will involve actually showing the item being dragged. What is the easiest way to do this? The items I am dragging are nothing really special,but I am not even sure where to look for how to do this.
我一直在研究WPF应用程序,它本质上是一个WYSIWYG编辑器,并且正在使用拖放功能。我有拖放功能,但需要使其更直观和用户友好。部分内容涉及实际显示被拖动的项目。最简单的方法是什么?我拖的项目并不特别,但我甚至不确定在哪里寻找如何做到这一点。
1 个解决方案
#1
8
You will need to make use of DragDrop.GiveFeedback amongst other things; Jaime has a great blog post outlining varying scenarios of which the one you describe is included.
你需要使用DragDrop.GiveFeedback等等; Jaime有一篇很棒的博客文章,概述了你所描述的不同场景。
Trivial example from Jaime's blog post in dealing with cursor manipulation...
来自Jaime博客文章处理光标操作的简单例子......
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 { }
}
#1
8
You will need to make use of DragDrop.GiveFeedback amongst other things; Jaime has a great blog post outlining varying scenarios of which the one you describe is included.
你需要使用DragDrop.GiveFeedback等等; Jaime有一篇很棒的博客文章,概述了你所描述的不同场景。
Trivial example from Jaime's blog post in dealing with cursor manipulation...
来自Jaime博客文章处理光标操作的简单例子......
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 { }
}