/// <summary> /// Gets the current content that is stored in the clipboard object. /// </summary> /// <returns>Contains the content of the Clipboard.</returns> public static DataPackageView GetContent() { #if __ANDROID__ if(_clipboardManager.HasPrimaryClip) { DataPackage package = new DataPackage(); if (_clipboardManager.PrimaryClipDescription != null) { package.Properties.Description = _clipboardManager.PrimaryClipDescription.Label; } ClipData data = _clipboardManager.PrimaryClip; for (int i = 0; i < data.ItemCount; i++) { ClipData.Item item = data.GetItemAt(i); if (!string.IsNullOrEmpty(item.Text)) { package.SetText(item.Text); } else if(item.Uri != null) { package.SetWebLink(new Uri(item.Uri.ToString())); } } return package.GetView(); } #elif __IOS__ if(UIPasteboard.General.Count > 0) { DataPackage package = new DataPackage(); var str = UIPasteboard.General.String; if(!string.IsNullOrEmpty(str)) { package.SetText(str); } var url = UIPasteboard.General.Url; if(url != null) { package.SetWebLink(new Uri(url.ToString())); } return package.GetView(); } #elif __MAC__ if(!string.IsNullOrEmpty(NSPasteboard.GeneralPasteboard.GetAvailableTypeFromArray(new string[] { NSPasteboard.NSPasteboardTypeString}))) { DataPackage package = new DataPackage(); string str = NSPasteboard.GeneralPasteboard.GetStringForType(NSPasteboard.NSPasteboardTypeString); if (!string.IsNullOrEmpty(str)) { package.SetText(str); } return package.GetView(); } #elif WINDOWS_PHONE_APP if(_on10) { var dpv = _type10.GetRuntimeMethod("GetContent", new Type[0]).Invoke(null, new object[0]) as Windows.ApplicationModel.DataTransfer.DataPackageView; if(dpv != null) { DataPackage package = new DataPackage(); if (!string.IsNullOrEmpty(dpv.Properties.Title)) { package.Properties.Title = dpv.Properties.Title; } if (!string.IsNullOrEmpty(dpv.Properties.Description)) { package.Properties.Description = dpv.Properties.Description; } foreach (string format in dpv.AvailableFormats) { if (format == StandardDataFormats.ApplicationLink || format == StandardDataFormats.WebLink || format == StandardDataFormats.Text) { Task<object> t = Task.Run<object>(async () => { return await dpv.GetDataAsync(format); }); t.Wait(); package.SetData(format, t.Result); } } return package.GetView(); } } #elif WIN32 string txt = GetText(); if(!string.IsNullOrEmpty(txt)) { DataPackage package = new DataPackage(); package.SetText(txt); return package.GetView(); } #else throw new PlatformNotSupportedException(); #endif return null; }
/// <summary> /// Gets the current content that is stored in the clipboard object. /// </summary> /// <returns>Contains the content of the Clipboard.</returns> public static DataPackageView GetContent() { #if __ANDROID__ if (_clipboardManager.HasPrimaryClip) { DataPackage package = new DataPackage(); if (_clipboardManager.PrimaryClipDescription != null) { package.Properties.Description = _clipboardManager.PrimaryClipDescription.Label; } ClipData data = _clipboardManager.PrimaryClip; for (int i = 0; i < data.ItemCount; i++) { ClipData.Item item = data.GetItemAt(i); if (!string.IsNullOrEmpty(item.Text)) { package.SetText(item.Text); } else if (item.Uri != null) { package.SetWebLink(new Uri(item.Uri.ToString())); } } return(package.GetView()); } #elif __IOS__ if (UIPasteboard.General.Count > 0) { DataPackage package = new DataPackage(); var str = UIPasteboard.General.String; if (!string.IsNullOrEmpty(str)) { package.SetText(str); } var url = UIPasteboard.General.Url; if (url != null) { package.SetWebLink(new Uri(url.ToString())); } return(package.GetView()); } #elif __MAC__ if (!string.IsNullOrEmpty(NSPasteboard.GeneralPasteboard.GetAvailableTypeFromArray(new string[] { NSPasteboard.NSPasteboardTypeString }))) { DataPackage package = new DataPackage(); string str = NSPasteboard.GeneralPasteboard.GetStringForType(NSPasteboard.NSPasteboardTypeString); if (!string.IsNullOrEmpty(str)) { package.SetText(str); } return(package.GetView()); } #elif WINDOWS_PHONE_APP if (_on10) { var dpv = _type10.GetRuntimeMethod("GetContent", new Type[0]).Invoke(null, new object[0]) as Windows.ApplicationModel.DataTransfer.DataPackageView; if (dpv != null) { DataPackage package = new DataPackage(); if (!string.IsNullOrEmpty(dpv.Properties.Title)) { package.Properties.Title = dpv.Properties.Title; } if (!string.IsNullOrEmpty(dpv.Properties.Description)) { package.Properties.Description = dpv.Properties.Description; } foreach (string format in dpv.AvailableFormats) { if (format == StandardDataFormats.ApplicationLink || format == StandardDataFormats.WebLink || format == StandardDataFormats.Text) { Task <object> t = Task.Run <object>(async() => { return(await dpv.GetDataAsync(format)); }); t.Wait(); package.SetData(format, t.Result); } } return(package.GetView()); } } #elif WIN32 string txt = GetText(); if (!string.IsNullOrEmpty(txt)) { DataPackage package = new DataPackage(); package.SetText(txt); return(package.GetView()); } #else throw new PlatformNotSupportedException(); #endif return(null); }