MainWindow.xaml.csの全コード
using System;
using System.Windows;
namespace DropFiles
{
public partial class MainWindow : Window
{
IDataObject dataObj;
String[] FileName;
public MainWindow()
{
InitializeComponent();
TextBlock1.AllowDrop = true;
//TextBlock1.Drop += new DragEventHandler(TextBlock1_Drop);
//TextBlock1.DragEnter += new DragEventHandler(TextBlock1_DragEnter);
//TextBlock1.DragLeave += new DragEventHandler(TextBlock1_DragLeave);
}
private void TextBlock1_Drop(object sender, DragEventArgs e)
{
dataObj = e.Data as IDataObject;
String[] FileName = dataObj.GetData(DataFormats.FileDrop) as String[];
TextBox1.Text = "Drop " + FileName[0];
}
private void TextBlock1_DragEnter(object sender, DragEventArgs e)
{
dataObj = e.Data as IDataObject;
String[] FileName = dataObj.GetData(DataFormats.FileDrop) as String[];
TextBox1.Text = "DragEnter " + FileName[0];
}
private void TextBlock1_DragLeave(object sender, DragEventArgs e)
{
dataObj = e.Data as IDataObject;
String[] FileName = dataObj.GetData(DataFormats.FileDrop) as String[];
TextBox1.Text = "DragLeave " + FileName[0];
}
}
}