在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
新闻热点
疑难解答