【发布时间】:2017-08-01 10:15:19
【问题描述】:
所以大约一年前,我在 WinForm 中开发这个应用程序,并决定在 WPF 中重新创建它以使其更多。我猜是最新的。 我刚刚遇到了我的第一个问题,允许拖放。 当我尝试拖放文件时,它不起作用,因为它给了我一个黑色圆圈,一条线穿过它。
这是我迄今为止尝试过的。 设置 AllowDrop = true。
在 Stack 上测试一些解决方案
测试了这个 http://codeinreview.com/136/enabling-drag-and-drop-over-a-grid-in-wpf/
但是我用谷歌搜索了多少我找不到答案,所以我问专业人士。 把它放在我身上我做错了什么,我将如何以正确的方式做到这一点? 这是我到目前为止的代码
<Grid AllowDrop="True" Drop="Grid_Drop" DragOver="Grid_DragOver">
<TextBox Name="tbSomething" Text="stuff" Margin="181,140,183,152"></TextBox>
</Grid>
private void Grid_Drop(object sender, DragEventArgs e)
{
if (null != e.Data && e.Data.GetDataPresent(DataFormats.FileDrop))
{
var data = e.Data.GetData(DataFormats.FileDrop) as string[];
// handle the files here!
}
}
private void Grid_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.Copy;
}
else
{
e.Effects = DragDropEffects.None;
}
}
【问题讨论】:
-
...您是否尝试设置断点?
标签: c# wpf drag-and-drop