-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathShareImage.xaml.cs
100 lines (90 loc) · 3.56 KB
/
ShareImage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//<SnippetHowToShareImageDeferral_CS>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel.DataTransfer;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ShareMainBetaCS
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ShareImage : Page
{
private StorageFile imageFile = null;
private RandomAccessStreamReference imageStreamRef = null;
private RandomAccessStreamReference dataPackageThumbnail = null;
public ShareImage()
{
this.InitializeComponent();
pickImageButton.Click += new RoutedEventHandler(pickImageButton_Click);
this.ShareSourceLoad();
}
async void pickImageButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker imagePicker = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
};
this.imageFile = await imagePicker.PickSingleFileAsync();
if (this.imageFile != null)
{
this.imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);
this.dataPackageThumbnail = this.imageStreamRef;
}
}
public void ShareSourceLoad()
{
DataTransferManager datatransferManager;
datatransferManager = DataTransferManager.GetForCurrentView();
datatransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}
//<SnippetHowToShareImage_CS>
//<SnippetHowToShareImage>
void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
//<SnippetDataRequestDeferral_CS>
//<SnippetDataRequestDeferral>
DataRequestDeferral deferral = e.Request.GetDeferral();
//</SnippetDataRequestDeferral>
//</SnippetDataRequestDeferral_CS>
e.Request.Data.Properties.Title = "Hello World!";
e.Request.Data.Properties.Description = "This example shows how to share files and images.";
//<SnippetAddThumbnailForImage_CS>
if (this.dataPackageThumbnail != null)
{
e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
}
//</SnippetAddThumbnailForImage_CS>
//<SnippetSetBitmap_CS>
//<SnippetSetBitmap>
e.Request.Data.SetBitmap(imageStreamRef);
//</SnippetSetBitmap>
//</SnippetSetBitmap_CS>
//<SnippetDeferralComplete_CS>
//<SnippetDeferralComplete>
deferral.Complete();
//</SnippetDeferralComplete_CS>
//</SnippetDeferralComplete>
}
//</SnippetHowToShareImage>
//</SnippetHowToShareImage_CS>
}
}
//</SnippetHowToShareImageDeferral_CS>