当前位置: 首页>>代码示例>>C#>>正文


C# DataPackage.SetStorageItems方法代码示例

本文整理汇总了C#中Windows.ApplicationModel.DataTransfer.DataPackage.SetStorageItems方法的典型用法代码示例。如果您正苦于以下问题:C# DataPackage.SetStorageItems方法的具体用法?C# DataPackage.SetStorageItems怎么用?C# DataPackage.SetStorageItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.ApplicationModel.DataTransfer.DataPackage的用法示例。


在下文中一共展示了DataPackage.SetStorageItems方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyButton_Click

        async void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            OutputText.Text = "Storage Items: ";
            var filePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                FileTypeFilter = { "*" }
            };

            var storageItems = await filePicker.PickMultipleFilesAsync();
            if (storageItems.Count > 0)
            {
                OutputText.Text += storageItems.Count + " file(s) are copied into clipboard";
                var dataPackage = new DataPackage();
                dataPackage.SetStorageItems(storageItems);

                // Request a copy operation from targets that support different file operations, like File Explorer
                dataPackage.RequestedOperation = DataPackageOperation.Copy;
                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 file was selected.";
            }
        }
开发者ID:mbin,项目名称:Win81App,代码行数:33,代码来源:CopyFile.xaml.cs

示例2: ShareFileAsync

        private async Task ShareFileAsync(DashboardViewModel vm, DataPackage dataPackage, DataPackagePropertySet propertySet)
        {
            var cleanFileName = vm.SelectedItem.ImagePath.Replace(@"../Images/", "");

            var packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var imagesFolder = await packageLocation.GetFolderAsync("Images");
            var imageToShare = await imagesFolder.GetFileAsync(cleanFileName);

            dataPackage.SetStorageItems(new List<IStorageItem>{imageToShare});

            var imageStreamRef = RandomAccessStreamReference.CreateFromFile(imageToShare);
            propertySet.Thumbnail = imageStreamRef;

        }
开发者ID:derikwhittaker,项目名称:LiveLessons.WinRT,代码行数:14,代码来源:DashboardPage.xaml.cs

示例3: MainPage_DataRequested

        private async void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var GetFiles = args.Request.GetDeferral();
            try
            {
                var name = String.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpg", "MyApp", DateTime.Now);
                StorageFolder tempFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MidTermTemp", CreationCollisionOption.ReplaceExisting);
                StorageFile saveItem = await tempFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
                byte[] pixels;
                using (Stream pixelStream = srcWriteAbleBitmap.PixelBuffer.AsStream())
                {
                    pixels = new byte[pixelStream.Length];
                    pixelStream.Read(pixels, 0, pixels.Length);
                    for (int i = 0; i < pixels.Length; i += 4)
                    {
                        byte temp = pixels[i];
                        pixels[i] = pixels[i + 2];
                        pixels[i + 2] = temp;
                    }
                }
                using (IRandomAccessStream fileStream = await saveItem.OpenAsync(FileAccessMode.ReadWrite))
                {
                    BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, fileStream);
                    encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
                        (uint)srcWriteAbleBitmap.PixelWidth, (uint)srcWriteAbleBitmap.PixelHeight, 96, 96, pixels);
                    await encoder.FlushAsync();
                    using (var outputStream = fileStream.GetOutputStreamAt(0))
                    {
                        await outputStream.FlushAsync();
                    }
                }

                DataPackage data = new DataPackage();
                data.Properties.Title = "共享图片";
                data.Properties.Description = "分享一些内容。";
                List<IStorageItem> files = new List<IStorageItem>();
                files.Add(saveItem);
                data.SetStorageItems(files);
                args.Request.Data = data;
            }
            finally
            {
                GetFiles.Complete();
            }
        }
开发者ID:12330375,项目名称:Booom,代码行数:45,代码来源:BasicPage1.xaml.cs

示例4: FillPackage

		private static void FillPackage(StorageFile[] files, DataPackage package, object subShareItem)
		{
			if (subShareItem != null)
			{
				switch (subShareItem.GetType().Name)
				{
					case nameof(TextShareItem):
						{
							package.SetText((subShareItem as TextShareItem).Text);
						}
						break;
					case nameof(ApplicationLinkShareItem):
						{
							var sitm = subShareItem as ApplicationLinkShareItem;
							package.SetApplicationLink(sitm.ApplicationLink);
						}
						break;

					case nameof(DelayRenderedImageShareItem):
						{
							var sitm = subShareItem as DelayRenderedImageShareItem;
							package.SetBitmap(RandomAccessStreamReference.CreateFromStream(sitm.SelectedImage.GetRandowmAccessStream()));
						}
						break;

					case nameof(FilesShareItem):
						{
							StorageFile[] resultArray = files;
							package.SetStorageItems(resultArray);
						}
						break;
					case nameof(HtmlShareItem):
						{
							var sitm = subShareItem as HtmlShareItem;

							var fmt = HtmlFormatHelper.CreateHtmlFormat(sitm.HtmlFragment);
							package.SetHtmlFormat(fmt);
							package.SetText(sitm.HtmlFragment);

						}
						break;
					case nameof(WebLinkShareItem):
						{
							var sitm = subShareItem as WebLinkShareItem;
							package.SetWebLink(sitm.WebLink);
							package.SetText(sitm.WebLink?.ToString());

						}
						break;

					default:
						break;
				}

			}
		}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:56,代码来源:DefaultShareService.cs

示例5: CopyFiles

        public override string CopyFiles(IList<FileInfoM> files)
        {
            string errorMessage = string.Empty;

            if (files.Any(p => p.StorageFile == null) || files.Any(p => (p.StorageFile is StorageFile) == false))
            {
                errorMessage = "Have no StorageFiles";
                return errorMessage;
            }

            var dataPackage = new DataPackage();
            var storageFiles = (from kkk in files
                select kkk.StorageFile).Cast<StorageFile>().ToList();
            dataPackage.SetStorageItems(storageFiles, true);
            dataPackage.RequestedOperation = DataPackageOperation.Copy;
            try
            {
                Clipboard.SetContent(dataPackage);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return errorMessage;
        }
开发者ID:vapps,项目名称:CrossPlatform,代码行数:26,代码来源:StoreAppStorageUtility.cs

示例6: CopyFile

        public override string CopyFile(FileInfoM file)
        {
            string errorMessage = string.Empty;

            if (file.StorageFile == null || (file.StorageFile is StorageFile) == false)
            {
                errorMessage = "Have no StorageFile";
                return errorMessage;
            }

            var dataPackage = new DataPackage();
            dataPackage.SetStorageItems(new List<StorageFile> {(StorageFile) file.StorageFile}, true);
            dataPackage.RequestedOperation = DataPackageOperation.Copy;
            try
            {
                Clipboard.SetContent(dataPackage);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            return errorMessage;
        }
开发者ID:vapps,项目名称:CrossPlatform,代码行数:23,代码来源:StoreAppStorageUtility.cs


注:本文中的Windows.ApplicationModel.DataTransfer.DataPackage.SetStorageItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。