Beispiel #1
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var key = parameter as StateItemKey;

            if (key != null && SessionState.Contains(key))
            {
                ShareOperation = SessionState.Get <ShareOperation>(key);
            }
            else
            {
                Content = "Opened without using share";
                return;
            }

            try
            {
                if (this.ShareOperation.Data.Contains(StandardDataFormats.Html))
                {
                    Content = (await ShareOperation.Data.GetHtmlFormatAsync()).ToString();
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.Text))
                {
                    Content = (await ShareOperation.Data.GetTextAsync()).ToString();
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.WebLink))
                {
                    Content = (await ShareOperation.Data.GetWebLinkAsync()).AbsoluteUri;
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.ApplicationLink))
                {
                    Content = (await ShareOperation.Data.GetApplicationLinkAsync()).AbsoluteUri;
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.Bitmap))
                {
                    Content = nameof(StandardDataFormats.Bitmap);
                    var bitmap = await ShareOperation.Data.GetBitmapAsync();

                    using (var stream = await bitmap.OpenReadAsync())
                    {
                        Bitmap = new BitmapImage();
                        Bitmap.SetSource(stream);
                    }
                }
                else if (ShareOperation.Data.Contains(StandardDataFormats.StorageItems))
                {
                    Content = nameof(StandardDataFormats.StorageItems);
                    foreach (var item in await ShareOperation.Data.GetStorageItemsAsync())
                    {
                        Content += item.Path + Environment.NewLine;
                    }
                }
                else
                {
                    Content = "Some unsupported share type.";
                    return;
                }

                QuickLink = ShareOperation.QuickLinkId ?? "None set";

                if (ShareOperation.Data.Properties.Square30x30Logo != null)
                {
                    using (var stream = await ShareOperation.Data.Properties.Square30x30Logo.OpenReadAsync())
                    {
                        Logo = new BitmapImage();
                        Logo.SetSource(stream);
                    }
                }

                if (ShareOperation.Data.Properties.Thumbnail != null)
                {
                    using (var stream = await ShareOperation.Data.Properties.Thumbnail.OpenReadAsync())
                    {
                        Thumbnail = new BitmapImage();
                        Thumbnail.SetSource(stream);
                    }
                }
            }
            catch (Exception e) { Content = e.Message; }
            finally
            {
                var folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");

                var file = await folder.GetFileAsync("T10 56x56.png");

                var reference = RandomAccessStreamReference.CreateFromFile(file);
                var quick     = new QuickLink()
                {
                    Id        = "Template10 QuickLink",
                    Title     = "Template10 QuickLink",
                    Thumbnail = reference,
                };
                quick.SupportedFileTypes.Clear();
                quick.SupportedFileTypes.Add(StandardDataFormats.Text);
                quick.SupportedFileTypes.Add(StandardDataFormats.WebLink);
                quick.SupportedFileTypes.Add(StandardDataFormats.ApplicationLink);
                quick.SupportedFileTypes.Add(StandardDataFormats.Bitmap);
                quick.SupportedFileTypes.Add(StandardDataFormats.Html);
                ShareOperation.ReportCompleted(quick);
            }
        }