C#:WPF 中的拖放(Richtextbox)
我想在 WPF 中实现拖放机制,但它不起作用...... 使用Windows-Forms它可以工作,...
首先我将AllowDrop设置为True。在 Windows 窗体中,您已经可以将项目拖动到 RichTextBox 中,并且光标会发生变化。
对于 WPF .... 什么也没有发生。
下一点:实现 DragEnter 和 DragDrop 方法。 我按照在线手册上的说明做了。 (好吧,我必须尝试更多东西,因为 WPF 中不存在 DragDrop) 我认为所有拖放教程仅适用于 Windowsforms,没有适用于 WPF...
richtextbox 有问题吗?如果我将其更改为“allowDrop” - 什么也不会发生。光标仍然是不允许的符号。
希望有人可以提供帮助:)
我读过的教程中的示例代码:
richTextBox1.AllowDrop = true;
void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.XXX))
{
e.Effect = DragDropEffects.Copy;
}
}
void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
//intert in richtextbox ...
richTextBox1.methodeXY();
}
i want to implement a Drag/Drop mechanic in WPF, but it didn't work...
With Windows-Forms it worked, ...
First i set AllowDrop to True. In windows-forms you can already drag items into the richtextbox and the cursor changes.
With WPF .... nothing happens.
The nexT point: Implement DragEnter and DragDrop Methodes.
I did it like the online-manuals says. (ok i had to try out something more, because DragDrop doesn't exists in WPF)
I think all tutorials for drag/drop is only for Windowsforms, nothing for WPF...
Is there a problem with the richtextbox? If i change it to "allowDrop" - nothing happens. The cursor is still a not-allowed-symbol.
Hope someone can help :)
Examplecode from tutorials i read:
richTextBox1.AllowDrop = true;
void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.XXX))
{
e.Effect = DragDropEffects.Copy;
}
}
void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
//intert in richtextbox ...
richTextBox1.methodeXY();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很好奇为什么,所以我玩了一下,最终让它工作了。本质上,我首先绑定到 PreviewXXX 事件,如下所示:
即使如此,它们仍然不起作用。但答案是这里,其形式为提升的权限。我通常以管理员权限运行 VS2010。因为我将一些文件从资源管理器拖放到我的
RichTextBox
上,所以它实际上禁止了该操作,因为资源管理器在非提升用户模式下运行。在非提升模式下运行 VS2010 解决了该问题。链接的文章确实提出了一些解决方法,但我还没有尝试过。I was curious as to why so I had a little play and eventually got it to work. Essentially, I started by binding to the PreviewXXX events like so:
Even still, they STILL didn't work. But the answer came here, in the form of elevated permissions. I usually run VS2010 with admin elevation. Because I was dropping some files from Explorer onto my
RichTextBox
, it was essentially banning the operation because Explorer runs in a non-elevated user mode. Running the VS2010 in a non-elevated mode fixed the problem. The article linked does suggest some workarounds, but I haven't tried them yet.