码迷,mamicode.com
首页 > Windows程序 > 详细

解决WPF中TextBox文件拖放问题

时间:2017-01-17 10:25:02      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:参考   and   send   处理   textbox   如何   drop   span   text   

在WPF中,当我们尝试向TextBox中拖放文件,从而获取其路径时,往往无法成功(拖放文字可以成功)。造成这种原因关键是WPF的TextBox对拖放事件处理机制的不同,具体可参考这篇文章Textbox Drag/Drop in WPF,本文只是介绍如何解决这一问题。

解放方法如下:

使用PreviewDragOver和PreviewDrop事件代替DragOver和Drop事件。

<TextBox Height=”100″ PreviewDragOver=”TextBox_PreviewDragOver” PreviewDrop=”TextBox_PreviewDrop”/>

 

在PreviewDragOver事件中加入e.Handled = true操作。

private void TextBox_PreviewDragOver(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Copy;
e.Handled = true;
}

 

解决WPF中TextBox文件拖放问题

标签:参考   and   send   处理   textbox   如何   drop   span   text   

原文地址:http://www.cnblogs.com/wzwyc/p/6291874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!