SetWebLink() public method

Sets the web link that a DataPackage contains.
Whenever possible, you should set this property. A source app provides a value for this property, and a target app reads the value. Use this property to indicate the source of the shared content.
public SetWebLink ( Uri value ) : void
value System.Uri A URI with an http or https scheme that corresponds to the content being displayed to the user.
return void
示例#1
0
        /// <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;
        }
示例#2
0
        /// <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);
        }