WFP实现将textbox中的文字拖进label并显示

167 阅读1分钟

在这里插入图片描述
在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);
}