拖放文件不起作用WPF [英] Drag and Drop a File is not working WPF

查看:102
本文介绍了拖放文件不起作用WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试将文件从桌面拖放到WPF应用程序。但它不起作用。我写了一个代码获取拖拽文件,例如,


 如果( e.Data.GetDataPresent(DataFormats.FileDrop, true ))
{
string [] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true as [];
}





并试试这个,



  if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// 请注意,您可以拥有多个文件。
string [] files =( string [])e.Data.GetData(DataFormats.FileDrop);

// 假设您有一个您关心的文件,请将其传递给任何
// 处理您定义的代码。

}





但这两个代码对我不起作用。请帮帮我。谢谢。

解决方案

尝试以下链接 -

http://msdn.microsoft.com/en-us/library/ms742859.aspx [ ^ ]

在WPF中拖放 [ ^ ]

http:/ /wpftutorial.net/DragAndDrop.html [ ^ ]

Hi,
I try to drag and drop a file from desktop to WPF application. But its not working. I written a code get the drag file like,

if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];
            }



and also try''d this,

if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // Note that you can have more than one file.
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                // Assuming you have one file that you care about, pass it off to whatever
                // handling code you have defined.

            }



But both code not working for me. Please help me on this. Thank you.

解决方案

Try the following links -
http://msdn.microsoft.com/en-us/library/ms742859.aspx[^]
Drag and Drop in WPF[^]
http://wpftutorial.net/DragAndDrop.html[^]


这篇关于拖放文件不起作用WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆