WPF-Base/WPF路由事件-8-鼠标拖拽/MainWindow.xaml.cs

27 lines
706 B
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WPF路由事件_8_鼠标拖拽;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void LabelDrop1_OnDrop(object sender, DragEventArgs e)
{
e.Effects = e.Data.GetDataPresent(DataFormats.Text) ? DragDropEffects.Copy : DragDropEffects.None;
}
private void LabelDrop1_OnMouseDown(object sender, MouseButtonEventArgs e)
{
var label = (Label)sender;
DragDrop.DoDragDrop(label, LabelDrop1.Content, DragDropEffects.Copy);
}
}