Esempio n. 1
0
        /// <summary>
        ///  共有の<c>DataPackageView</c>からこのクラスのインスタンスを作成する.
        /// </summary>
        /// <param name="package">共有の<c>DataPackageView</c></param>
        /// <returns>このクラスのインスタンス</returns>
        public static async Task <SharedBitmapItem> CreateFromDataPackage(DataPackageView package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            if (!package.Contains(StandardDataFormats.Bitmap))
            {
                return(null);
            }

            var bmpStream = await package.GetBitmapAsync();

            using (var bmpStreamWithContentType = await bmpStream.OpenReadAsync())
            {
                var bmpImage = new BitmapImage();
                bmpImage.SetSource(bmpStreamWithContentType);

                var item = new SharedBitmapItem(bmpImage);
                await item.KeepSharedBitmapInfoAsync(bmpStreamWithContentType);

                return(item);
            }
        }
        /// <summary>
        ///  貼り付けのポップアップの中身をクリップボードを参照して設定する.
        /// </summary>
        private async void PreparePastePopupContentsAsync()
        {
            var dataPackageView = Clipboard.GetContent();
            var sharedItems     = new List <ISharedItem>();

            var bmpItem = await SharedBitmapItem.CreateFromDataPackage(dataPackageView);

            if (bmpItem != null)
            {
                sharedItems.Add(bmpItem);
            }

            var stgItems = await SharedStorageFileItem.CreateFromDataPackage(dataPackageView);

            if (stgItems != null)
            {
                foreach (var stgItem in stgItems)
                {
                    sharedItems.Add(stgItem);
                }
            }
            if (sharedItems.Count == 0)
            {
                this.PasteAppBarButton.IsEnabled = false;
                return;
            }

            this.pastedItemsView.ItemsSource = sharedItems;
            this.pastedItemsView.SelectAll();
            this.PasteAppBarButton.IsEnabled = true;
        }
Esempio n. 3
0
        /// <summary>
        ///  共有データに含まれる画像とファイルを登録候補として追加する.
        /// </summary>
        /// <param name="shareOperation"></param>
        private async void AddSharedItemsAsync(ShareOperation shareOperation)
        {
            var bmpItem = await SharedBitmapItem.CreateFromDataPackage(shareOperation.Data);

            if (bmpItem != null)
            {
                this.sharedItems.Add(bmpItem);
            }

            var stgItems = await SharedStorageFileItem.CreateFromDataPackage(shareOperation.Data);

            if (stgItems != null)
            {
                foreach (var stgItem in stgItems)
                {
                    this.sharedItems.Add(stgItem);
                }
            }

            this.SharedItemsView.SelectAll();
        }