Wpf解决TextBox文件拖入问题、拖放问题

在WPF中,当我们尝试向TextBox中拖放文件,从而获取其路径时,往往无法成功(拖放文字可以成功)。造成这种原因关键是WPF的TextBox对拖放事件处理机制的不同,

解放方法如下:    

    1. 使用PreviewDragOver和PreviewDrop事件代替DragOver和Drop事件。
      <TextBox Height="100" PreviewDragOver="TextBox_PreviewDragOver" PreviewDrop="TextBox_PreviewDrop"/>
    2. 在PreviewDragOver事件中加入e.Handled = true操作。
      private void TextBox_PreviewDragOver(object sender, DragEventArgs e)
      {
          e.Effects = DragDropEffects.Copy;
          e.Handled = true;
      }
原文地址:https://www.cnblogs.com/tianma3798/p/5466521.html