Image
img2
からImage
img1
からドラッグアンドドロップする必要があります。つまり、img1
にドラッグすると、img2
をコピーしたいということです。プログラムは起動していますが、宛先Image
img1
は、Image
img2
をドラッグしても変更されていません。イメージドラッグアンドドロップ(WPFウィンドウ)
この問題を解決するにはどうすればいいですか?
以下の私のコード:
XAML:
<Canvas Name="va">
<Image Name="img1" Height="100" Width="100" AllowDrop="True" Drop="img1_Drop" />
<Image Name="img2" Height="100" Width="100" Source="Resources/eye.bmp"
MouseLeftButtonDown="img2_MouseLeftButtonDown" AllowDrop="True" />
</Canvas>
C#コード:
private void img2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Image image = e.Source as Image;
DataObject data = new DataObject(typeof(ImageSource), image.Source);
DragDrop.DoDragDrop(image, data, DragDropEffects.All);
}
private void img1_Drop(object sender, DragEventArgs e)
{
Image imageControl = (Image)sender;
if ((e.Data.GetData(typeof(ImageSource)) != null))
{
ImageSource image = e.Data.GetData(typeof(ImageSource)) as ImageSource;
imageControl = new Image() { Width = 100, Height = 100, Source = image };
img1 = imageControl;
}
}
マインド:
はあなたではなく、単に
img1
のSource
プロパティを割り当てる必要があります。 –ここに良い例がありますhttps://www.strathweb.com/2012/06/drag-and-drop-files-to-wpf-application-and-asynchronously-upload-to-asp-net-web-api/ –