當前位置: 首頁>>代碼示例>>C#>>正文


C# DataPackage.SetDataProvider方法代碼示例

本文整理匯總了C#中Windows.ApplicationModel.DataTransfer.DataPackage.SetDataProvider方法的典型用法代碼示例。如果您正苦於以下問題:C# DataPackage.SetDataProvider方法的具體用法?C# DataPackage.SetDataProvider怎麽用?C# DataPackage.SetDataProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.ApplicationModel.DataTransfer.DataPackage的用法示例。


在下文中一共展示了DataPackage.SetDataProvider方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CopyBitmap

        async private void CopyBitmap(bool isDelayRendered)
        {
            var imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
            };

            var imageFile = await imagePicker.PickSingleFileAsync();
            if (imageFile != null)
            {
                var dataPackage = new DataPackage();

                // Use one click handler for two operations: regular copy and copy using delayed rendering
                // Differentiate the case by the button name
                if (isDelayRendered)
                {
                    dataPackage.SetDataProvider(StandardDataFormats.Bitmap, request => OnDeferredImageRequestedHandler(request, imageFile));
                    OutputText.Text = "Image has been copied using delayed rendering";
                }
                else
                {
                    dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
                    OutputText.Text = "Image has been copied";
                }

                try
                {
                    Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
                }
                catch (Exception ex)
                {
                    // Copying data to Clipboard can potentially fail - for example, if another application is holding Clipboard open
                    rootPage.NotifyUser("Error copying content to Clipboard: " + ex.Message + ". Try again", NotifyType.ErrorMessage);
                }
            }
            else
            {
                OutputText.Text = "No image was selected.";
            }
        }
開發者ID:oldnewthing,項目名稱:old-Windows8-samples,代碼行數:42,代碼來源:CopyImage.xaml.cs


注:本文中的Windows.ApplicationModel.DataTransfer.DataPackage.SetDataProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。