简单的拖拽实现:
<Grid x:Name="G1" AllowDrop="True" DragEnter="G1_DragEnter"
Drop="G1_Drop"
Background="Green"/>
private void G1_DragEnter(object sender, DragEventArgs e)
{
e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
} private async void G1_Drop(object sender, DragEventArgs e)
{
var fileFromDesktop = (StorageFile)(await e.DataView.GetStorageItemsAsync())[];
var bitImg = new BitmapImage();
bitImg.SetSource(await fileFromDesktop.OpenReadAsync());
var imageControl = new Image();
imageControl.Source = bitImg;
G1.Children.Add(imageControl);
}
复杂的可以参考这博客:Windows 10 - Modern Drag and Drop for Windows Universal Applications
实现了异步执行Drop,相关的代码在这。