我正在尝试为 WPF 中的 ImageControl 实现 DragAndDrop。我使用 C# 代码隐藏将图像添加到网格。
System.Windows.Controls.Image OldMan = new System.Windows.Controls.Image();
OldMan.Height=30;
OldMan.Width=30;
OldMan.Name="OldMan";
OldMan.Margin=new Thickness(100,100,0,0);
OldMan.HorizontalAlignment=System.Windows.HorizontalAlignment.Left;
OldMan.Stretch = Stretch.Fill;
OldMan.VerticalAlignment = System.Windows.VerticalAlignment.Top;
OldMan.Source= ConvertBitmap(Properties.Resources.Old1);
OldMan.MouseDown += new MouseButtonEventHandler(OldMan_MouseDown);
//PW is the name of my Grid
PW.Children.Add(OldMan);
PW.RegisterName(OldMan.Name, OldMan);
这会将 Image 添加到网格中,并挂钩到 MouseDown 事件
在 MouseDown 事件中
void OldMan_MouseDown(object sender, MouseButtonEventArgs e)
{
System.Windows.Controls.Image img = (System.Windows.Controls.Image)sender;
DoDragDrop(.... //this doesn't exist so obviously I am missing something
}
所以我没有 DoDragDrop 选项,所以我有什么选择