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(); } }
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); }
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(); } }
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(); } }
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; } } } } } } }
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(); }
// 从剪切板中获取文件并保存到指定的路径 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 内容"; } }
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(); } }
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(); } }
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(); } }
private async void MainPage_OnDrop(object sender, DragEventArgs e) { // 记得获取Deferral对象 var def = e.GetDeferral(); DataPackageView data = e.DataView; // 还是再验证一下吧,防止意外 if (data.Contains(StandardDataFormats.StorageItems)) { var storageItems = await data.GetStorageItemsAsync(); if (storageItems.Count > 0) { var item = storageItems[0]; StorageFile file = item as StorageFile; // 生成内存图像 if (file != null) { ImageViewPage.Create(file); } } } VisualStateManager.GoToState(this, "Generic", false); // 报告操作系统,处理完成 def.Complete(); }
private async Task ShowSharedStorageItems(DataPackageView shareData) { DefaultViewModel["IsStorageItemsShared"] = true; var storageItems = await shareData.GetStorageItemsAsync(); DefaultViewModel["SharedStorageItems"] = storageItems.Select(x => x.Name).ToList(); }
private async void Viewbox_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)); PhoneBitmap = bitmap; _filepath = file.Path; } } var PhoneInfo = _filepath.Split('_'); if (PhoneInfo.Count() >= 5) { PhoneOEM.Text = UpperFirst(PhoneInfo[2]); if (PhoneOEM.Text == "Samsung") { PhoneName.Text = "Galaxy " + UpperFirst(PhoneInfo[3]); } PhoneName.Text = UpperFirst(PhoneInfo[3]); string ColorStr = ""; int index; if (PhoneInfo[5].IndexOf('-') > 0) { index = PhoneInfo[5].IndexOf('-'); ColorStr = UpperFirst(PhoneInfo[5].Substring(0, index)); } else if (PhoneInfo[6].IndexOf('-') > 0) { index = PhoneInfo[6].IndexOf('-'); ColorStr = UpperFirst(PhoneInfo[6].Substring(0, index)); PhoneName.Text += (" " + UpperFirst(PhoneInfo[4])); } if (ColorToStr(ColorStr) != null) { Color.SelectedValue = ColorStr; } } } finally { defer.Complete(); } }
private static async Task ProcessComandsAsync(DropConfiguration configuration, DataPackageView dataview) { if (configuration.OnDropDataViewCommand != null) { configuration.OnDropDataViewCommand.Execute(dataview); } if (dataview.Contains(StandardDataFormats.ApplicationLink) && configuration.OnDropApplicationLinkCommand != null) { var uri = await dataview.GetApplicationLinkAsync(); configuration.OnDropApplicationLinkCommand.Execute(uri); } if (dataview.Contains(StandardDataFormats.Bitmap) && configuration.OnDropBitmapCommand != null) { var stream = await dataview.GetBitmapAsync(); configuration.OnDropBitmapCommand.Execute(stream); } if (dataview.Contains(StandardDataFormats.Html) && configuration.OnDropHtmlCommand != null) { var html = await dataview.GetHtmlFormatAsync(); configuration.OnDropHtmlCommand.Execute(html); } if (dataview.Contains(StandardDataFormats.Rtf) && configuration.OnDropRtfCommand != null) { var rtf = await dataview.GetRtfAsync(); configuration.OnDropRtfCommand.Execute(rtf); } if (dataview.Contains(StandardDataFormats.StorageItems) && configuration.OnDropStorageItemsCommand != null) { var storageItems = await dataview.GetStorageItemsAsync(); configuration.OnDropStorageItemsCommand.Execute(storageItems); } if (dataview.Contains(StandardDataFormats.Text) && configuration.OnDropTextCommand != null) { var text = await dataview.GetTextAsync(); configuration.OnDropTextCommand.Execute(text); } if (dataview.Contains(StandardDataFormats.WebLink) && configuration.OnDropWebLinkCommand != null) { var uri = await dataview.GetWebLinkAsync(); configuration.OnDropWebLinkCommand.Execute(uri); } }
public async Task ProcessComandsAsync(DataPackageView dataview) { if (DropDataViewAction != null) { DropDataViewAction.Invoke(dataview); } if (dataview.Contains(StandardDataFormats.ApplicationLink) && DropApplicationLinkAction != null) { Uri uri = await dataview.GetApplicationLinkAsync(); DropApplicationLinkAction.Invoke(uri); } if (dataview.Contains(StandardDataFormats.Bitmap) && DropBitmapAction != null) { RandomAccessStreamReference stream = await dataview.GetBitmapAsync(); DropBitmapAction.Invoke(stream); } if (dataview.Contains(StandardDataFormats.Html) && DropHtmlAction != null) { string html = await dataview.GetHtmlFormatAsync(); DropHtmlAction.Invoke(html); } if (dataview.Contains(StandardDataFormats.Rtf) && DropRtfAction != null) { string rtf = await dataview.GetRtfAsync(); DropRtfAction.Invoke(rtf); } if (dataview.Contains(StandardDataFormats.StorageItems) && DropStorageItemsAction != null) { IReadOnlyList <IStorageItem> storageItems = await dataview.GetStorageItemsAsync(); DropStorageItemsAction.Invoke(storageItems); } if (dataview.Contains(StandardDataFormats.Text) && DropTextAction != null) { string text = await dataview.GetTextAsync(); DropTextAction.Invoke(text); } if (dataview.Contains(StandardDataFormats.WebLink) && DropWebLinkAction != null) { Uri uri = await dataview.GetWebLinkAsync(); DropWebLinkAction.Invoke(uri); } }
public async Task ProcessComandsAsync(DataPackageView dataview) { if (DropDataViewAction != null) { DropDataViewAction.Invoke(dataview); } if (dataview.Contains(StandardDataFormats.ApplicationLink) && DropApplicationLinkAction != null) { var uri = await dataview.GetApplicationLinkAsync(); DropApplicationLinkAction.Invoke(uri); } if (dataview.Contains(StandardDataFormats.Bitmap) && DropBitmapAction != null) { var stream = await dataview.GetBitmapAsync(); DropBitmapAction.Invoke(stream); } if (dataview.Contains(StandardDataFormats.Html) && DropHtmlAction != null) { var html = await dataview.GetHtmlFormatAsync(); DropHtmlAction.Invoke(html); } if (dataview.Contains(StandardDataFormats.Rtf) && DropRtfAction != null) { var rtf = await dataview.GetRtfAsync(); DropRtfAction.Invoke(rtf); } if (dataview.Contains(StandardDataFormats.StorageItems) && DropStorageItemsAction != null) { var storageItems = await dataview.GetStorageItemsAsync(); DropStorageItemsAction.Invoke(storageItems); } if (dataview.Contains(StandardDataFormats.Text) && DropTextAction != null) { var text = await dataview.GetTextAsync(); DropTextAction.Invoke(text); } if (dataview.Contains(StandardDataFormats.WebLink) && DropWebLinkAction != null) { var uri = await dataview.GetWebLinkAsync(); DropWebLinkAction.Invoke(uri); } }
private async Task InsertItems(DataPackageView dataview, ObservableCollection <CustomItem> target) { if (dataview.Contains(StandardDataFormats.StorageItems)) { var items = await dataview.GetStorageItemsAsync(); foreach (StorageFile item in items) { target.Add(await CustomItemFactory.Create(item)); } } }
public async void PasteItem_ClickAsync(object sender, RoutedEventArgs e) { string DestinationPath = CurrentInstance.ViewModel.Universal.WorkingDirectory; int oldCount = CurrentInstance.ViewModel.FilesAndFolders.Count; DataPackageView packageView = Clipboard.GetContent(); ItemsToPaste = await packageView.GetStorageItemsAsync(); itemsPasted = 0; if (ItemsToPaste.Count > 3) { (App.CurrentInstance as ProHome).UpdateProgressFlyout(InteractionOperationType.PasteItems, itemsPasted, ItemsToPaste.Count); } foreach (IStorageItem item in ItemsToPaste) { if (item.IsOfType(StorageItemTypes.Folder)) { CloneDirectoryAsync(item.Path, DestinationPath, item.Name, false); } else if (item.IsOfType(StorageItemTypes.File)) { if (ItemsToPaste.Count > 3) { (App.CurrentInstance as ProHome).UpdateProgressFlyout(InteractionOperationType.PasteItems, ++itemsPasted, ItemsToPaste.Count); } StorageFile ClipboardFile = await StorageFile.GetFileFromPathAsync(item.Path); await ClipboardFile.CopyAsync(await StorageFolder.GetFolderFromPathAsync(DestinationPath), item.Name, NameCollisionOption.GenerateUniqueName); } } if (packageView.RequestedOperation == DataPackageOperation.Move) { foreach (string path in App.pathsToDeleteAfterPaste) { if (path.Contains(".")) { StorageFile file = await StorageFile.GetFileFromPathAsync(path); await file.DeleteAsync(); } if (!path.Contains(".")) { StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path); await folder.DeleteAsync(); } } } }
internal static async Task <string> SetData(DataPackageView data) { string type = ""; if (data.Contains(StandardDataFormats.StorageItems)) { var items = await data.GetStorageItemsAsync(); var files = items.Where(x => x is StorageFile).Select(x => x as StorageFile).ToList(); string url = ""; if ((files.Count == 1) && ((files[0].FileType.ToLower() == ".html") /* Edge */ || (files[0].FileType.ToLower() == ".url") /* Chrome + Firefox */) && ((url = await IsALink(files[0])) != "")) { SendDataTemporaryStorage.LaunchUri = new Uri(url); SendDataTemporaryStorage.Text = url; type = StandardDataFormats.WebLink; } else if ((files.Count == 0) && (items.Count == 1) && (items[0] is StorageFolder)) { SendDataTemporaryStorage.Files = new List <IStorageItem>(items); type = StandardDataFormats.StorageItems; } else { SendDataTemporaryStorage.Files = new List <IStorageItem>(files); type = StandardDataFormats.StorageItems; } } else if (data.Contains(StandardDataFormats.WebLink)) { SendDataTemporaryStorage.LaunchUri = await data.GetWebLinkAsync(); SendDataTemporaryStorage.Text = SendDataTemporaryStorage.LaunchUri.OriginalString; type = StandardDataFormats.WebLink; } else if (data.Contains(StandardDataFormats.ApplicationLink)) { SendDataTemporaryStorage.LaunchUri = await data.GetApplicationLinkAsync(); SendDataTemporaryStorage.Text = SendDataTemporaryStorage.LaunchUri.OriginalString; type = StandardDataFormats.ApplicationLink; } else if (data.Contains(StandardDataFormats.Text)) { SendDataTemporaryStorage.Text = await data.GetTextAsync(); type = StandardDataFormats.Text; } return(type); }
// 拖动进入目标区域时发生 private async void Draggrid_DragEnter(object sender, DragEventArgs e) { var deferral = e.GetDeferral(); DataPackageView dataview = e.DataView; if (dataview.Contains(StandardDataFormats.StorageItems)) { var items = await dataview.GetStorageItemsAsync(); if (items != null) { IStorageItem item = items[0]; if (item.IsOfType(StorageItemTypes.File)) { e.AcceptedOperation = DataPackageOperation.Link; StorageFile file = (StorageFile)item; // 使用using块避免出现Thumbnail不可用的异常 using (StorageItemThumbnail img = await file.GetScaledImageAsThumbnailAsync(ThumbnailMode.VideosView)) { if (img != null) { BitmapImage bmp = new BitmapImage() { DecodePixelWidth = 150 }; bmp.SetSource(img); e.DragUIOverride.SetContentFromBitmapImage(bmp); } } // e.DragUIOverride.Caption = file.DisplayName; // e.DragUIOverride.IsCaptionVisible = false; if (file.ContentType.Split('/')[0] == "video") { dragfile = file; } } else { // 不用 DataPackageOperation.None 原因:不是约定的用法 deferral.Complete(); return; } } } else { deferral.Complete(); return; } // dragarea.Background.Opacity = 0; deferral.Complete(); }
async void Paste() { DataPackageView dataPackageView = Clipboard.GetContent(); if (dataPackageView.Contains(StandardDataFormats.StorageItems)) { var fl = await dataPackageView.GetStorageItemsAsync(); var f = fl.FirstOrDefault(); CopyFiltToResourceFolder(f as StorageFile); AddItem(f as StorageFile); } }
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 == ".jpeg" || file.FileType == ".gif") { // 拖放的是图片文件。 string constpath = "D:\\UWP-master\\NavDemo\\NavDemo\\"; int flag = 1; for (int i = 0; i < constpath.Length; ++i) { if (file.Path[i] != constpath[i]) { flag = 0; break; } } if (flag == 0) { await new Windows.UI.Popups.MessageDialog("请选择在工程文件夹下的图片,否则无效").ShowAsync(); return; } else { StrongTypeViewModel.friend.iconFriend = "ms-appx:///" + file.Path.Substring(constpath.Length); } BitmapImage bitmap = new BitmapImage(); await bitmap.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read)); imageBrushFriend.ImageSource = bitmap; } } } finally { defer.Complete(); } }
public async Task<string> clipboard(DataPackageView con) { string str = string.Empty; //文本 if (con.Contains(StandardDataFormats.Text)) { str = await con.GetTextAsync(); return str; } //图片 if (con.Contains(StandardDataFormats.Bitmap)) { RandomAccessStreamReference img = await con.GetBitmapAsync(); var imgstream = await img.OpenReadAsync(); Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); bitmap.SetSource(imgstream); Windows.UI.Xaml.Media.Imaging.WriteableBitmap src = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight); src.SetSource(imgstream); Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(imgstream); Windows.Graphics.Imaging.PixelDataProvider pxprd = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage); byte[] buffer = pxprd.DetachPixelData(); str = "image"; StorageFolder folder = await _folder.GetFolderAsync(str); StorageFile file = await folder.CreateFileAsync(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + (ran.Next() % 10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName); using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, fileStream); encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer); await encoder.FlushAsync(); str = $"![这里写图片描述](image/{file.Name})\n"; } } //文件 if (con.Contains(StandardDataFormats.StorageItems)) { var filelist = await con.GetStorageItemsAsync(); StorageFile file = filelist.OfType<StorageFile>().First(); return await imgfolder(file); } return str; }
private async Task PasteStorageFiles(DataPackageView dataPackageView) { var pasteContent = await dataPackageView.GetStorageItemsAsync(); foreach (var content in pasteContent) { var file = content as StorageFile; if (file == null) { continue; } await TryAddMedia(file); } }
private async void LayoutRoot_Drop(object sender, DragEventArgs e) { var defer = e.GetDeferral(); try { DataPackageView dataView = e.DataView; if (dataView.Contains(StandardDataFormats.StorageItems)) { var files = await dataView.GetStorageItemsAsync(); var file = files.OfType <StorageFile>().First(); if (file.FileType == ".png" || file.FileType == ".jpg" || file.FileType == ".bmp") { this.file = file; var bi = new BitmapImage(); IRandomAccessStream s = await file.OpenAsync(FileAccessMode.Read); await bi.SetSourceAsync(s); photo.Source = bi; mode = SendMode.Photo; } else if (file.FileType == ".txt") { string text = await FileIO.ReadTextAsync(file); send.Text = text.Length > 140 ? text.Substring(0, 140) : text; } } else if (dataView.Contains(StandardDataFormats.Text)) { string text = await dataView.GetTextAsync(); send.Text = text.Length > 140 ? text.Substring(0, 140) : text; } else if (dataView.Contains(StandardDataFormats.Rtf)) { string text = await dataView.GetRtfAsync(); send.Text = text.Length > 140 ? text.Substring(0, 140) : text; } } finally { defer.Complete(); } }
public static async void PasteItem_ClickAsync(object sender, RoutedEventArgs e) { var DestinationPath = App.ViewModel.Universal.path; DataPackageView packageView = Clipboard.GetContent(); var oldCount = App.ViewModel.FilesAndFolders.Count; var ItemsToPaste = await packageView.GetStorageItemsAsync(); foreach (IStorageItem item in ItemsToPaste) { if (item.IsOfType(StorageItemTypes.Folder)) { CloneDirectoryAsync(item.Path, DestinationPath, item.Name); } else if (item.IsOfType(StorageItemTypes.File)) { StorageFile ClipboardFile = await StorageFile.GetFileFromPathAsync(item.Path); await ClipboardFile.CopyAsync(await StorageFolder.GetFolderFromPathAsync(DestinationPath), item.Name, NameCollisionOption.GenerateUniqueName); } } if (packageView.RequestedOperation == DataPackageOperation.Move) { foreach (string path in pathsToDeleteAfterPaste) { if (path.Contains(".")) { StorageFile file = await StorageFile.GetFileFromPathAsync(path); await file.DeleteAsync(); } if (!path.Contains(".")) { StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path); await folder.DeleteAsync(); } } } if (page.Name == "GenericItemView") { NavigationActions.Refresh_Click(null, null); } else if (page.Name == "PhotoAlbumViewer") { PhotoAlbumNavActions.Refresh_Click(null, null); } }
private async void TextBox_Clipboard(object sender, TextControlPasteEventArgs e) { DataPackageView data = Clipboard.GetContent(); if (data != null) { if (data.Contains(StandardDataFormats.Bitmap)) { await SetClipimage(data); } else if (data.Contains(StandardDataFormats.StorageItems)) { StorageFile file = (await data.GetStorageItemsAsync()).First() as StorageFile; await ImageStorageFile(file); } } }
private async void HandleDataPackage(DataPackageView data, string imagefilename) { if (data.Contains(StandardDataFormats.StorageItems)) { foreach (var file in await data.GetStorageItemsAsync()) { AddAttachement(file as StorageFile); } } else if (data.Contains(StandardDataFormats.Bitmap)) { var bmpDPV = await data.GetBitmapAsync(); var bmpSTR = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(imagefilename + ".png", CreationCollisionOption.OpenIfExists); using (var writeStream = (await bmpSTR.OpenStreamForWriteAsync()).AsRandomAccessStream()) using (var readStream = await bmpDPV.OpenReadAsync()) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(readStream.CloneStream()); BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, writeStream); encoder.SetSoftwareBitmap(await decoder.GetSoftwareBitmapAsync()); await encoder.FlushAsync(); AddAttachement(bmpSTR); } } else if (data.Contains(StandardDataFormats.Text)) { Editor.Text = await data.GetTextAsync(); } else if (data.Contains(StandardDataFormats.WebLink)) { Editor.Text = (await data.GetWebLinkAsync()).ToString(); } else if (data.Contains(StandardDataFormats.ApplicationLink)) { Editor.Text = (await data.GetApplicationLinkAsync()).ToString(); } else if (data.Contains(StandardDataFormats.Html)) { var converter = new Html2Markdown.Converter(); Editor.Text = converter.Convert(await data.GetHtmlFormatAsync()); } }
private async Task InsertItems(DataPackageView dataview, ObservableCollection <CustomItem> target) { if (dataview.Contains(StandardDataFormats.StorageItems)) { var items = await dataview.GetStorageItemsAsync(); foreach (StorageFile item in items) { target.Add(new CustomItem { Path = item.Path, FileName = item.Name, Image = await GetImageOrDefaultAsync(item), OriginalStorageItem = item }); } } }
public async Task Paste(DataPackageView dataView, CanvasControl control = null) { IRandomAccessStreamWithContentType stream = null; try { if (dataView.Contains(StandardDataFormats.Bitmap)) { var data = await dataView.GetBitmapAsync(); stream = await data.OpenReadAsync(); } else if (dataView.Contains(StandardDataFormats.StorageItems)) { var items = await dataView.GetStorageItemsAsync(); if (items.Count > 0) { var(IsImage, Stream) = await TryParseImage(items[0]); if (IsImage) { stream = Stream; } } } if (stream != null) { var bitmap = await CanvasBitmap.LoadAsync(control ?? this.canvas, stream); this.Update(bitmap); } } catch (Exception e) { Debug.WriteLine(e.GetType() + ":\n" + e);//ignore } finally { stream?.Dispose(); } }