-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathMainPage.xaml.cs
108 lines (94 loc) · 4.02 KB
/
MainPage.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
101
102
103
104
105
106
107
108
using System;
// <Snippetcs_TargetAppNamespaces>
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.ShareTarget;
// </Snippetcs_TargetAppNamespaces>
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Streams;
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;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ShareTargetBetaCS
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public partial class MainPage
{
public MainPage()
{
InitializeComponent();
}
// <Snippetcs_HandleShare>
public async Task ActivateAsync(ShareTargetActivatedEventArgs args)
{
// <Snippetcs_HandleSharedText>
ShareOperation shareOperation = args.ShareOperation;
if (shareOperation.Data.Contains(StandardDataFormats.Text))
{
string text = await shareOperation.Data.GetTextAsync();
// To output the text from this example, you need a TextBlock control
// with a name of "sharedContent".
sharedContent.Text = "Text: " + text;
}
// </Snippetcs_HandleSharedText>
if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
{
// <Snippetcs_ReportStarted>
shareOperation.ReportStarted();
// </Snippetcs_ReportStarted>
IReadOnlyList<IStorageItem> storageItems = null;
storageItems = await shareOperation.Data.GetStorageItemsAsync();
string fileList = String.Empty;
for (int index = 0; index < storageItems.Count; index++)
{
fileList += storageItems[index].Name;
if (index < storageItems.Count - 1) {
fileList += ", ";
}
}
// To output the text from this example, you need a TextBlock control
// with a name of "sharedContent".
sharedContent.Text += "StorageItems: " + fileList + Environment.NewLine;
shareOperation.ReportCompleted();
}
Window.Current.Content = this;
Window.Current.Activate();
}
// </Snippetcs_HandleShare>
// Note that the following code if for snippeting only. It's not actually called in
// this app. It's derived from the SharingTarget sample, so I'm confident it works.
// <Snippetcs_HowToCreateAQuickLink>
async void ReportCompleted(ShareOperation shareOperation, string quickLinkId, string quickLinkTitle)
{
QuickLink quickLinkInfo = new QuickLink
{
Id = quickLinkId,
Title = quickLinkTitle,
// For quicklinks, the supported FileTypes and DataFormats are set
// independently from the manifest
SupportedFileTypes = { "*" },
SupportedDataFormats = { StandardDataFormats.Text, StandardDataFormats.Uri,
StandardDataFormats.Bitmap, StandardDataFormats.StorageItems }
};
StorageFile iconFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFileAsync(
"assets\\user.png", CreationCollisionOption.OpenIfExists);
quickLinkInfo.Thumbnail = RandomAccessStreamReference.CreateFromFile(iconFile);
shareOperation.ReportCompleted(quickLinkInfo);
}
// </Snippetcs_HowToCreateAQuickLink>
}
}