Exemplo n.º 1
0
        // 显示剪切板中的 html 数据
        private async void btnPasteHtml_Click(object sender, RoutedEventArgs e)
        {
            DataPackageView dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Html))
            {
                try
                {
                    // 封装后的数据
                    string htmlFormat = await dataPackageView.GetHtmlFormatAsync();

                    // 封装前的数据
                    string htmlFragment = HtmlFormatHelper.GetStaticFragment(htmlFormat);

                    lblMsg.Text  = "htmlFormat(封装后的数据): ";
                    lblMsg.Text += Environment.NewLine;
                    lblMsg.Text += htmlFormat;
                    lblMsg.Text += Environment.NewLine;
                    lblMsg.Text += Environment.NewLine;
                    lblMsg.Text += "htmlFragment(封装前的数据): ";
                    lblMsg.Text += Environment.NewLine;
                    lblMsg.Text += htmlFragment;
                }
                catch (Exception ex)
                {
                    lblMsg.Text = ex.ToString();
                }
            }
            else
            {
                lblMsg.Text = "剪切板中无 html 内容";
            }
        }
Exemplo n.º 2
0
        public static async Task <IReadOnlyList <string> > GetAsPathListAsync(this DataPackageView View)
        {
            List <string> PathList = new List <string>();

            if (View.Contains(StandardDataFormats.StorageItems))
            {
                PathList.AddRange((await View.GetStorageItemsAsync()).Select((Item) => Item.Path));
            }

            if (View.Contains(StandardDataFormats.Text))
            {
                string XmlText = await View.GetTextAsync();

                if (XmlText.Contains("RX-Explorer"))
                {
                    XmlDocument Document = new XmlDocument();
                    Document.LoadXml(XmlText);

                    IXmlNode KindNode = Document.SelectSingleNode("/RX-Explorer/Kind");

                    if (KindNode?.InnerText == "RX-Explorer-TransferNotStorageItem")
                    {
                        PathList.AddRange(Document.SelectNodes("/RX-Explorer/Item").Select((Node) => Node.InnerText));
                    }
                }
            }

            return(PathList);
        }
Exemplo n.º 3
0
        private async void MusicDrop(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dpv = e.DataView;
                if (dpv.Contains(StandardDataFormats.StorageItems))
                {
                    IReadOnlyList <IStorageItem> files = await dpv.GetStorageItemsAsync();

                    if (NowPlayingDargOverEvent != null)
                    {
                        NowPlayingDargOverEvent(new NowPlayingDragOverEventArgs()
                        {
                            Items = (from StorageFile file in files where file.ContentType == "audio/mpeg" && file.IsOfType(StorageItemTypes.File) select file).ToList()
                        });
                    }
                }
            }
            finally
            {
                defer.Complete();
            }
        }
Exemplo n.º 4
0
        private async void MusicDragOver(object sender, DragEventArgs e)
        {
            var deferral = e.GetDeferral();

            e.DragUIOverride.Caption = "播放";
            DataPackageView dataview = e.DataView;

            if (dataview.Contains(StandardDataFormats.StorageItems))
            {
                var items = await dataview.GetStorageItemsAsync();

                if (items.Count > 0)
                {
                    List <StorageFile> files = (from IStorageItem file in items where file.IsOfType(StorageItemTypes.File) select file as StorageFile).ToList();
                    if (files.Count > 0)
                    {
                        e.AcceptedOperation = DataPackageOperation.Copy;
                    }
                    else
                    {
                        e.AcceptedOperation = DataPackageOperation.None;
                    }
                }
            }
            else
            {
                e.AcceptedOperation = DataPackageOperation.None;
            }
            deferral.Complete();
        }
Exemplo n.º 5
0
        private async void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (IsCtrlKeyPressed())
            {
                if (e.Key == VirtualKey.V)
                {
                    DataPackageView dataPackageView = Clipboard.GetContent();
                    if (dataPackageView.Contains(StandardDataFormats.StorageItems))
                    {
                        var p = await dataPackageView.GetStorageItemsAsync();

                        if (p.Count == 1)
                        {
                            if (p[0] is StorageFile f)
                            {
                                if (f.ContentType.Contains("image"))
                                {
                                    var guid   = Guid.NewGuid();
                                    var copied = await f.CopyAsync(ApplicationData.Current.LocalCacheFolder, guid.ToString() + f.FileType, NameCollisionOption.ReplaceExisting);

                                    (Window.Current.Content as Frame).Navigate(typeof(ResultPage), new Uri(copied.Path));
                                    e.Handled = true;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private async void OcrClipboardButton_Click(object sender, RoutedEventArgs e)
        {
            DisableOcrButtons();
            this.ErrorMessageGrid.Visibility = Visibility.Collapsed;

            DataPackageView dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference sr = await dataPackageView.GetBitmapAsync();

                // ※ RandomAccessStreamReference は Dispose 不要

                if (sr != null)
                {
                    if (this.MonitorCameraButton.IsChecked == true)
                    {
                        this.MonitorCameraButton.IsChecked = false;
                    }

                    using (var stream = await sr.OpenReadAsync())
                    {
                        var bitmap = await SoftwareBitmapHelper.ConvertToSoftwareBitmap(stream);
                        await SetImage(bitmap);
                        await RecognizeBitmapAsync(bitmap);
                    }
                }
            }
            else
            {
                await(new MessageDialog("クリップボードに画像がありません", "画像なし"))
                .ShowAsync();
            }
            EnableOcrButtons();
        }
Exemplo n.º 7
0
        // 履歴を取得する基本的な流れ(説明用)
        public static async Task GetClipboardHistoryAsync()
        {
            if (!Clipboard.IsHistoryEnabled())
            {
                return; // 設定で履歴が無効にされている
            }
            var result = await Clipboard.GetHistoryItemsAsync();

            // 履歴の取得に失敗したときは、result.Statusに
            // Success以外(AccessDeniedまたはClipboardHistoryDisabled)が返される
            if (result.Status != ClipboardHistoryItemsResultStatus.Success)
            {
                return;
            }

            // 履歴のリストを取り出す
            IReadOnlyList <ClipboardHistoryItem> historyList = result.Items;

            // それぞれの履歴アイテムを処理する
            foreach (ClipboardHistoryItem item in historyList)
            {
                // 履歴アイテムのIDとタイムスタンプ
                string         id        = item.Id;
                DateTimeOffset timestamp = item.Timestamp;

                // データ(クリップボードのデータと同じ型)
                DataPackageView content = item.Content;

                // テキストデータを取り出す例
                if (content.Contains(StandardDataFormats.Text))
                {
                    string textData = await content.GetTextAsync();

                    // DataPackageViewに入っているデータは、
                    // このようにして非同期メソッドを使って取得する
                }

                // データとして入っているフォーマットの一覧
                List <string> formats = content.AvailableFormats.ToList();
                // content.AvailableFormatsはSystem.__ComObjectのリストなので、
                // ToList拡張メソッドを使って「こっちの世界に固定する」

                // 全てのデータを取りだす例
                foreach (string format in formats)
                {
                    object data = await content.GetDataAsync(format);

                    //Type dataType = data.GetType();
                    //if (dataType.FullName == "System.__ComObject")
                    //{
                    //  // ただし、GetTypeしてもSystem.__ComObject型が返ってきてしまい、
                    //  // その実体が何であるか不明なデータもある
                    //  var types = dataType.GetInterfaces(); //←ITypeInfoを実装していないのでは何だか分からない
                    //}
                }

                // ローミングされてクリップボードに入れられたデータかどうか
                bool isFromRoamingClipboard = content.Properties.IsFromRoamingClipboard;
            }
        }
Exemplo n.º 8
0
        // Note: this sample is not trying to resolve and render the HTML using resource map.
        // Please refer to the Clipboard JavaScript sample for an example of how to use resource map
        // for local images display within an HTML format. This sample will only demonstrate how to
        // get a resource map object and extract its key values
        async void DisplayResourceMapAsync(DataPackageView dataPackageView)
        {
            OutputResourceMapKeys.Text = Environment.NewLine + "Resource map: ";
            IReadOnlyDictionary <string, RandomAccessStreamReference> resMap = null;

            try
            {
                resMap = await dataPackageView.GetResourceMapAsync();
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("Error retrieving Resource map from Clipboard: " + ex.Message, NotifyType.ErrorMessage);
            }

            if (resMap != null)
            {
                if (resMap.Count > 0)
                {
                    foreach (var item in resMap)
                    {
                        OutputResourceMapKeys.Text += Environment.NewLine + "Key: " + item.Key;
                    }
                }
                else
                {
                    OutputResourceMapKeys.Text += Environment.NewLine + "Resource map is empty";
                }
            }
        }
Exemplo n.º 9
0
        private async void ButtonGetHtml_Click(object sender, RoutedEventArgs e)
        {
            DataPackageView clipboardContent = Clipboard.GetContent();

            if (clipboardContent.Contains(StandardDataFormats.Text))
            {
                rawCode = await clipboardContent.GetTextAsync();

                var rawDocument = new HtmlDocument();
                rawDocument.LoadHtml(rawCode);
                var baseNode = rawDocument.DocumentNode.Element("div");

                if (baseNode != null && baseNode.GetAttributeValue("class", "").Contains("WB_cardwrap"))
                {
                    var weiboPost = new WeiboPostParser(baseNode);
                    TextBoxMarkdownCode.Document.SetText(Windows.UI.Text.TextSetOptions.None, weiboPost.GetJekyllCode());
                }
                else
                {
                    MessageDialog dlgInvalidText = new MessageDialog("The text in system clipboard is invalid.", "Notice");
                    await dlgInvalidText.ShowAsync();
                }
            }
            else
            {
                MessageDialog dlgNoText = new MessageDialog("No text in system clipboard.", "Notice");
                await dlgNoText.ShowAsync();
            }
        }
Exemplo n.º 10
0
        private async Task PasteBitmapImage(DataPackageView dataPackageView)
        {
            IRandomAccessStreamReference imageReceived = null;

            imageReceived = await dataPackageView.GetBitmapAsync();

            if (imageReceived != null)
            {
                StorageFile file;
                using (var imageStream = await imageReceived.OpenReadAsync())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imageStream);

                    var softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                    file = await CreateBitmapFileWithUniqueName();

                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);

                        encoder.SetSoftwareBitmap(softwareBitmap);
                        encoder.IsThumbnailGenerated = false;
                        await encoder.FlushAsync();
                    }
                }

                await TryAddMedia(file);
            }
        }
Exemplo n.º 11
0
        private async void MainGrid_Drop(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dataView = e.DataView;
                // 拖放类型为文件存储。
                if (dataView.Contains(StandardDataFormats.StorageItems))
                {
                    var files = await dataView.GetStorageItemsAsync();

                    StorageFile file = files.OfType <StorageFile>().First();
                    if (file.FileType == ".png" || file.FileType == ".jpg")
                    {
                        BitmapImage bitmap = new BitmapImage();
                        await bitmap.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));

                        PhoneImageBrush.ImageSource = bitmap;
                        Messenger.Default.Send(new WidthHeight(bitmap.PixelWidth, bitmap.PixelHeight), "ImageWidthHeight");
                    }
                }
            }
            finally
            {
                defer.Complete();
            }
        }
Exemplo n.º 12
0
        public async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
        {
            DataPackageView packageView     = Clipboard.GetContent();
            string          destinationPath = CurrentInstance.ViewModel.WorkingDirectory;

            await PasteItems(packageView, destinationPath, packageView.RequestedOperation);
        }
Exemplo n.º 13
0
        public static async void PasteItemWithStatus(DataPackageView packageView, string destinationPath, DataPackageOperation acceptedOperation)
        {
            var CurrentInstance       = App.CurrentInstance;
            PostedStatusBanner banner = App.CurrentInstance.StatusBarControl.OngoingTasksControl.PostBanner(
                null,
                CurrentInstance.FilesystemViewModel.WorkingDirectory,
                0,
                StatusBanner.StatusBannerSeverity.Ongoing,
                StatusBanner.StatusBannerOperation.Paste);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await PasteItem(packageView, destinationPath, acceptedOperation, CurrentInstance, banner.Progress);

            banner.Remove();

            sw.Stop();

            if (sw.Elapsed.TotalSeconds >= 10)
            {
                App.CurrentInstance.StatusBarControl.OngoingTasksControl.PostBanner(
                    "Paste Complete",
                    "The operation has completed.",
                    0,
                    StatusBanner.StatusBannerSeverity.Success,
                    StatusBanner.StatusBannerOperation.Paste);
            }
        }
Exemplo n.º 14
0
        private void Clipboard_ContentChanged(object sender, object e)
        {
            if (App.InteractionViewModel == null)
            {
                return;
            }

            try
            {
                // Clipboard.GetContent() will throw UnauthorizedAccessException
                // if the app window is not in the foreground and active
                DataPackageView packageView = Clipboard.GetContent();
                if (packageView.Contains(StandardDataFormats.StorageItems) || packageView.Contains(StandardDataFormats.Bitmap))
                {
                    App.InteractionViewModel.IsPasteEnabled = true;
                }
                else
                {
                    App.InteractionViewModel.IsPasteEnabled = false;
                }
            }
            catch
            {
                App.InteractionViewModel.IsPasteEnabled = false;
            }
        }
Exemplo n.º 15
0
        // 从剪切板中获取文件并保存到指定的路径
        private async void btnPasteFile_Click(object sender, RoutedEventArgs e)
        {
            DataPackageView dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.StorageItems))
            {
                try
                {
                    IReadOnlyList <IStorageItem> storageItems = await dataPackageView.GetStorageItemsAsync();

                    StorageFile file = storageItems.First() as StorageFile;
                    if (file != null)
                    {
                        StorageFile newFile = await file.CopyAsync(ApplicationData.Current.TemporaryFolder, file.Name, NameCollisionOption.ReplaceExisting);

                        if (newFile != null)
                        {
                            lblMsg.Text = string.Format("已将文件从{0}复制到{1}", file.Path, newFile.Path);
                        }
                    }
                }
                catch (Exception ex)
                {
                    lblMsg.Text = ex.ToString();
                }
            }
            else
            {
                lblMsg.Text = "剪切板中无 StorageItems 内容";
            }
        }
Exemplo n.º 16
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dataView = e.DataView;
                if (dataView.Contains(StandardDataFormats.StorageItems))
                {
                    var files = await dataView.GetStorageItemsAsync();

                    StorageFile file = files.OfType <StorageFile>().First();
                    if ((file.FileType == ".png") || (file.FileType == ".jpg") ||
                        (file.FileType == ".gif"))
                    {
                        await ImageStorageFile(file);
                    }
                    _name = file.DisplayName;
                }
            }
            catch
            {
            }
            finally
            {
                defer.Complete();
            }
        }
Exemplo n.º 17
0
        //private void ShowSharedRtf(DataPackageView shareData)
        //{
        //    //throw new NotImplementedException();
        //}

        private async Task ShowSharedHtml(DataPackageView shareData)
        {
            DefaultViewModel["IsHtmlShared"]  = true;
            DefaultViewModel["IsHtmlLoading"] = true;

            var sharedHtmlContent = await shareData.GetHtmlFormatAsync();

            if (!String.IsNullOrEmpty(sharedHtmlContent))
            {
                // Convert the shared content that contains extra header data into just the working fragment
                var sharedHtmlFragment = HtmlFormatHelper.GetStaticFragment(sharedHtmlContent);

                // Reconcile any resource-mapped image references
                var sharedResourceMap = await shareData.GetResourceMapAsync();

                foreach (var resource in sharedResourceMap)
                {
                    var mappedImageElement     = String.Format("<img src={0}>", resource.Key);
                    var replacementImageBase64 = await resource.Value.Base64EncodeContent();

                    var replacementImageElement = String.Format("<img src='data:image/png;base64,{0}' />", replacementImageBase64);
                    var imageIndex = sharedHtmlFragment.IndexOf(mappedImageElement, StringComparison.Ordinal);
                    while (imageIndex >= 0)
                    {
                        sharedHtmlFragment = sharedHtmlFragment.Remove(imageIndex, mappedImageElement.Length);
                        sharedHtmlFragment = sharedHtmlFragment.Insert(imageIndex, replacementImageElement);
                        imageIndex         = sharedHtmlFragment.IndexOf(mappedImageElement, StringComparison.Ordinal);
                    }
                }

                DefaultViewModel["IsHtmlLoading"] = false;
                DefaultViewModel["SharedHtml"]    = sharedHtmlFragment;
            }
        }
Exemplo n.º 18
0
 public static void Clipboard_ContentChanged(object sender, object e)
 {
     try
     {
         if (App.CurrentInstance != null)
         {
             DataPackageView packageView = Clipboard.GetContent();
             if (packageView.Contains(StandardDataFormats.StorageItems) && App.CurrentInstance.CurrentPageType != typeof(YourHome))
             {
                 App.PS.isEnabled = true;
             }
             else
             {
                 App.PS.isEnabled = false;
             }
         }
         else
         {
             App.PS.isEnabled = false;
         }
     }
     catch (Exception)
     {
         App.PS.isEnabled = false;
     }
 }
Exemplo n.º 19
0
        private static async void Textbox_Paste(object sender, TextControlPasteEventArgs e)
        {
            e.Handled = true;
            DataPackageView dataPackageView = Clipboard.GetContent();

            if (!dataPackageView.Contains(StandardDataFormats.Text))
            {
                return;
            }

            var pasteText = await dataPackageView.GetTextAsync();

            if (string.IsNullOrWhiteSpace(pasteText))
            {
                return;
            }

            var textbox = (TextBox)sender;
            var mask    = textbox.GetValue(MaskProperty) as string;
            var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary <char, string>;
            var placeHolderValue         = textbox.GetValue(PlaceHolderProperty) as string;

            if (string.IsNullOrWhiteSpace(mask) ||
                representationDictionary == null ||
                string.IsNullOrEmpty(placeHolderValue))
            {
                return;
            }

            // to update the textbox text without triggering TextChanging text
            textbox.TextChanging -= Textbox_TextChanging;
            SetTextBoxValue(pasteText, textbox, mask, representationDictionary, placeHolderValue[0]);
            textbox.SetValue(OldTextProperty, textbox.Text);
            textbox.TextChanging += Textbox_TextChanging;
        }
Exemplo n.º 20
0
        public async Task Pasts()
        {
            vm.Loading = true;
            DataPackageView con = Clipboard.GetContent();

            if (con.Contains(StandardDataFormats.Bitmap))
            {
                var img = await con.GetBitmapAsync();

                WriteableBitmap src = await Img.CreateAsync(img);

                Exec.Do(new Exec()
                {
                    exec = delegate {
                        vm.LayerList.Insert(0, new LayerModel()
                        {
                            Bitmap = src
                        });
                        vm.CurrentLayer = vm.LayerList[0];
                    },
                    undo = delegate {
                        vm.LayerList.RemoveAt(0);
                        vm.CurrentLayer = vm.LayerList[0];
                    }
                });
            }
            else
            {
                await Task.Delay(500);
            }
            vm.Loading = false;
        }
Exemplo n.º 21
0
        // 显示剪切板中的图片内容
        private async void btnPasteImage_Click(object sender, RoutedEventArgs e)
        {
            DataPackageView dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                try
                {
                    IRandomAccessStreamReference randomStream = await dataPackageView.GetBitmapAsync();

                    if (randomStream != null)
                    {
                        using (IRandomAccessStreamWithContentType imageStream = await randomStream.OpenReadAsync())
                        {
                            BitmapImage bitmapImage = new BitmapImage();
                            bitmapImage.SetSource(imageStream);
                            imgBitmap.Source = bitmapImage;
                        }
                    }
                }
                catch (Exception ex)
                {
                    lblMsg.Text = ex.ToString();
                }
            }
            else
            {
                lblMsg.Text = "剪切板中无 bitmap 内容";
            }
        }
Exemplo n.º 22
0
        private async Task PasteHtmlFormat(DataPackageView dataPackageView)
        {
            var html = await dataPackageView.GetHtmlFormatAsync();

            var htmlFragment = HtmlFormatHelper.GetStaticFragment(html);
            await noteFieldView.HtmlEditor.InsertHtml(htmlFragment);
        }
Exemplo n.º 23
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dataView = e.DataView;
                if (dataView.Contains(StandardDataFormats.StorageItems))
                {
                    var files = await dataView.GetStorageItemsAsync();

                    StorageFile file = files.OfType <StorageFile>().First();
                    if ((file.FileType == ".png") || (file.FileType == ".jpg"))
                    {
                        BitmapImage bitmap = new BitmapImage();
                        await bitmap.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));

                        image.Source = bitmap;
                        View.Image   = bitmap;
                    }
                    _name = file.DisplayName;
                }
            }
            catch
            {
            }
            finally
            {
                defer.Complete();
            }
        }
Exemplo n.º 24
0
 public static void Clipboard_ContentChanged(object sender, object e)
 {
     try
     {
         if (App.CurrentInstance != null)
         {
             DataPackageView packageView = Clipboard.GetContent();
             if (packageView.Contains(StandardDataFormats.StorageItems) &&
                 App.CurrentInstance.CurrentPageType != typeof(YourHome) &&
                 !App.CurrentInstance.ViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath))
             {
                 App.PS.IsEnabled = true;
             }
             else
             {
                 App.PS.IsEnabled = false;
             }
         }
         else
         {
             App.PS.IsEnabled = false;
         }
     }
     catch (Exception)
     {
         App.PS.IsEnabled = false;
     }
 }
Exemplo n.º 25
0
        private async void DropImageIn(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dpv = e.DataView;
                if (dpv.Contains(StandardDataFormats.StorageItems))
                {
                    var files = await dpv.GetStorageItemsAsync();

                    foreach (var item in files)
                    {
                        if (item.Name.EndsWith(".jpg") || item.Name.EndsWith(".jpeg") || item.Name.EndsWith(".png"))
                        {
                            StorageFile file = StorageFile.GetFileFromPathAsync(item.Path).GetResults();
                            using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                await bitmapImage.SetSourceAsync(fileStream);

                                TheImage.Source = bitmapImage;
                            }
                            break;
                        }
                    }
                }
            }
            finally
            {
                defer.Complete();
            }
        }
Exemplo n.º 26
0
        public async Task <string?> TryGetTextAsync()
        {
            try
            {
                DataPackageView view = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

                // Try to extract the requested content
                string?item;
                if (view.Contains(StandardDataFormats.Text))
                {
                    item = await view.GetTextAsync();

                    view.ReportOperationCompleted(DataPackageOperation.Copy);
                }
                else
                {
                    item = null;
                }

                return(item);
            }
            catch
            {
                // Y u do dis?
                return(null);
            }
        }
Exemplo n.º 27
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);
            }
        }
Exemplo n.º 28
0
        private async void Grid_Drop(object sender, DragEventArgs e)
        {
            var defer = e.GetDeferral();

            try
            {
                DataPackageView dataView = e.DataView;
                // 拖放类型为文件存储。
                if (dataView.Contains(StandardDataFormats.StorageItems))
                {
                    var files = await dataView.GetStorageItemsAsync();

                    StorageFile file = files.OfType <StorageFile>().First();
                    if (file.FileType == ".png" || file.FileType == ".jpg")
                    {
                        // 拖放的是图片文件。
                        BitmapImage bitmap = new BitmapImage();
                        await bitmap.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));

                        ximg.ImageSource = bitmap;
                    }
                }
            }
            finally
            {
                defer.Complete();
            }
        }
        public static BaseViewItem GetViewItem(DataPackageView dataView)
        {
            object obj;

            dataView.Properties.TryGetValue("ViewItem", out obj);
            return(obj as BaseViewItem);
        }
Exemplo n.º 30
0
        public async Task <ReturnResult> PerformOperationTypeAsync(DataPackageOperation operation,
                                                                   DataPackageView packageView,
                                                                   string destination,
                                                                   bool registerHistory)
        {
            try
            {
                switch (operation)
                {
                case DataPackageOperation.Copy:
                    return(await CopyItemsFromClipboard(packageView, destination, registerHistory));

                case DataPackageOperation.Move:
                    return(await MoveItemsFromClipboard(packageView, destination, registerHistory));

                case DataPackageOperation.None:     // Other
                    return(await CopyItemsFromClipboard(packageView, destination, registerHistory));

                default: return(default);
                }
            }
            finally
            {
                packageView.ReportOperationCompleted(operation);
            }
        }
Exemplo n.º 31
0
 internal DataPackageViewAdapter( DataPackageView dataPackageView )
 {
     Contract.Requires( dataPackageView != null );
     adapted = dataPackageView;
     properties = new Lazy<IDataPackagePropertySetView>( () => new DataPackagePropertySetViewAdapter( adapted.Properties ) );
 }