Fork me on GitHub

UWP 共享文件——发送者

这一节,顾名思义,即使你要共享数据给别人,你是数据的提供者。

分两步即可
1、直接复制代码

protected override void OnNavigatedTo(NavigationEventArgs e)
{
DataTransferManager.GetForCurrentView().DataRequested += Page_DataRequested;
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
DataTransferManager.GetForCurrentView().DataRequested -= Page_DataRequested;
}

void Page_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
//Image
{
args.Request.Data.Properties.Title = "Exif Info Share";
args.Request.Data.Properties.Description = "From Exif Info";// The description is optional.
RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(file);
args.Request.Data.Properties.Thumbnail = imageStreamRef;
args.Request.Data.SetBitmap(imageStreamRef);

}
//StorageFile
{ 
//args.Request.Data.Properties.Title = "Exif Info Share";
//args.Request.Data.Properties.Description = "From Exif Info";// The description is optional.
//List<IStorageItem> files = new List<IStorageItem>();
//files.Add(file);
//args.Request.Data.SetStorageItems(files);
}
deferral.Complete();
}

 

2、最后

private void Btn_Share_Click(object sender, RoutedEventArgs e)
{
DataTransferManager.ShowShareUI();
}

 

posted @ 2017-10-02 16:07  猫叔Vincent  阅读(337)  评论(0编辑  收藏  举报