gpt4 book ai didi

c# - 如何在 WPF 中显示正在拖动的项目?

转载 作者:太空狗 更新时间:2023-10-29 20:18:23 24 4
gpt4 key购买 nike

我一直在开发一个 WPF 应用程序,它本质上是一个 WYSIWYG 编辑器,并且使用拖放功能。我有拖放功能,但需要使其更加直观和用户友好。其中一部分将涉及实际显示被拖动的项目。最简单的方法是什么?我拖动的项目并没有什么特别之处,但我什至不确定去哪里寻找如何执行此操作。

最佳答案

您需要使用 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 { }
}

关于c# - 如何在 WPF 中显示正在拖动的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4878004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com