LoginSignup
3
1

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-10-17

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だ。
 

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1