[WPF] TextBox に Drag&Drop する方法


TextBox にファイルを Drag&Drop するには
まずは Drop イベントハンドラを追加しよう。

a.xaml
<TextBox Drop="TextBox_Drop" PreviewDragOver="TextBox_PreviewDragOver">

中身は

a.xaml.cs
(string[])e.Data.GetData(System.Windows.Data.Formats.FileDrop)

で取り出そう。
 
気をつけるべきは PreviewDragOver イベントハンドラーも必要。
Window なら必要ないんだけどね。
ハンドラの中身は、

a.xaml.cs
e.Handled = true;

とだけ書けばOKだ。