在WPF中的實現和WinForm中的實現99%相似,將要實現接受拖拽釋放的控件添加DragEnter事件和Drop事件,本例中控件Grid grid作為接受控件,添加事件操作如下:
private
void grid_Drop(object sender, DragEventArgs e)
{
string
fileName =
((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
//獲得文件名後的操作...
}
private
void grid_DragEnter(object sender, DragEventArgs e)
{
if
(e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects =
DragDropEffects.Link;
//WinForm中為e.Effect =
DragDropEffects.Link
else e.Effects =
DragDropEffects.None;
//WinFrom中為e.Effect =
DragDropEffects.None
}
轉自:http://blog.sina.com.cn/s/blog_8679e2050100w20z.html