[英]WPF Window drag and drop not working
Why destination Image image1 is not changing after I drag Image img2 on it. 为什么在我将Image img2拖到目标Image image1之后没有更改。
My XAML Code: 我的XAML代码:
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="463.42" Width="861.214">
<Grid>
<Image Name="image1" Margin="291,10,297,94" AllowDrop="True" Source="C:/img/0.png" Drop="img1_Drop"/>
<Button x:Name="btn1" Content="merge" HorizontalAlignment="Left" Margin="753,392,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<Button Content="add" HorizontalAlignment="Left" Margin="658,392,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
</Grid>
Here is C# code: 这是C#代码:
private void img1_Drop(object sender, DragEventArgs e)
{
image1.Source = (System.Windows.Media.ImageSource)e.Data.GetData(typeof(System.Windows.Media.ImageSource));
//image1.Source = (BitmapImage)e.Data.GetData(DataFormats.Bitmap);
}
Nothing happens, how to solve this problem ? 什么都没发生,如何解决这个问题?
You can read the image directly from dropped filename info like this: 您可以像这样直接从删除的文件名信息中读取图像:
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
var filename = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
image1.Source = new BitmapImage(new Uri(filename));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.