在MainWindow.xmal文件中,
首先label的要添加
AllowDrop="True"
这样才能接收拖动事件
其次给label添加
PreviewDrop="label_PreviewDrop"
用来绑定拖进事件响应函数
在MainWindow.cs文件中,添加如下响应函数:
private void label_PreviewDrop(object sender, DragEventArgs e)
{
((Label)sender).Content = e.Data.GetData(DataFormats.Text);
}