码迷,mamicode.com
首页 > 其他好文 > 详细

UWP的拖拽功能

时间:2016-02-05 19:04:30      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

简单的拖拽实现:

        <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())[0];
            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,相关的代码在

 

UWP的拖拽功能

标签:

原文地址:http://www.cnblogs.com/qianblue/p/5183314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!