SetText() public method

public SetText ( [ value ) : void
value [
return void
示例#1
0
 private void Transfer_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
 {
     if (!Equals(null, VM))
     {
         DataPackage dp = new DataPackage();
         switch (VM.GetType().Name)
         {
             case "PictureViewModel":
                 dp.Properties.Title = "分享图片";
                 dp.SetText( $"一张图片,千言万语[来自ONE-UWP的分享]:{(VM as PictureViewModel).Picture.WebLk}");
                 break;
             case "ArticleViewModel":
                 dp.Properties.Title = "分享文章";
                 dp.SetText($"世间风情,字里行间[来自ONE-UWP的分享]:{(VM as ArticleViewModel).Article.WebLk}");
                 break;
             case "QuestionViewModel":
                 dp.Properties.Title = "分享问题";
                 dp.SetText($"每天一问,有问必答[来自ONE-UWP的分享]:{(VM as QuestionViewModel).Question.WebLk}");
                 break;
             case "ThingViewModel":
                 dp.Properties.Title = "分享东西";
                 dp.SetText($"友好世界,有好东西[来自ONE-UWP的分享]:{(VM as ThingViewModel).Thing.Wu}");
                 break;
         }
         args.Request.Data = dp;
     }
     else
     {
         return;
     }
 }
示例#2
0
 private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
 {
     var item = sender as MenuFlyoutItem;
     var User = item.DataContext as VipUser;
     var dp = new DataPackage();
     if (item.Name == "Account")
     {
         dp.SetText(User.Account);
     }
     else if (item.Name=="Password")
     {
         dp.SetText(User.Password);
     }
     Clipboard.SetContent(dp);
 }
        private async void Grid_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            Grid grid = (Grid)sender;
            Records.Items items = (Records.Items)grid.DataContext;
            String Data = String.Empty;
            ResourceLoader resourceLoader = new ResourceLoader();

            Data += String.Format(resourceLoader.GetString("pageResult_Assignment") + Environment.NewLine, items.Oid);
            Data += String.Format(resourceLoader.GetString("pageResult_Registry") + Environment.NewLine, items.RegistryID);
            Data += String.Format(resourceLoader.GetString("pageResult_OrganizationName") + Environment.NewLine, items.Name);
            Data += String.Format(resourceLoader.GetString("pageResult_OrganizationAddress") + Environment.NewLine, items.Address);

            if ( (items.Protocol != String.Empty) && (items.Protocol != null))
            {
                Data += String.Format(resourceLoader.GetString("pageResult_Protocol") + Environment.NewLine, items.Protocol);
            }

            DataPackage dataPackage = new DataPackage();

            dataPackage.SetText(Data);
            Clipboard.SetContent(dataPackage);

            MessageDialog msgbox = new MessageDialog(Data, resourceLoader.GetString("pageResult_DialogCopied"));

            msgbox.Commands.Clear();
            msgbox.Commands.Add(new UICommand { Label = resourceLoader.GetString("pageResult_DialogClose"), Id = 0 });
 
            var res = await msgbox.ShowAsync();
        }
示例#4
0
 public void SetText(string text)
 {
     var dp = new DataPackage();
     dp.SetText(text);
     Clipboard.SetContent(dp);
     UWPUtilities.GiveStatusBarFeedback("Copied to clipboard...");
 }
示例#5
0
 private void CopyButtonTapped(object sender, TappedRoutedEventArgs e)
 {
     var dataPackage = new DataPackage();
     dataPackage.SetText(this.tbCurrent.Text);
     Clipboard.SetContent(dataPackage);
     this.tbCopyed.Visibility = Visibility.Visible;
 }
示例#6
0
        private void Clipboard_Click(object sender, RoutedEventArgs e)
        {
            var dataPackage = new DataPackage();

            dataPackage.SetText(Match.AudioUrl);
            Clipboard.SetContent(dataPackage);
        }
示例#7
0
        private void Copy_Click(object sender, RoutedEventArgs e)
        {
            DataPackage data = new DataPackage();
            data.SetText(tbInput.Text);
            Clipboard.SetContent(data);

        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            XNamespace p_ns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
            XNamespace xaml_ns = "http://schemas.microsoft.com/winfx/2006/xaml";

            var doc = XDocument.Load(@"Common\StandardStyles.xaml");
            foreach (var style in doc.Descendants(p_ns + "Style"))
            {
                var key = style.Attribute(xaml_ns + "Key");
                if (key != null && key.Value != null)
                {
                    var basedOn = style.Attribute("BasedOn");
                    if (basedOn != null && basedOn.Value == @"{StaticResource AppBarButtonStyle}")
                    {
                        var button = new Button();
                        button.Style = App.Current.Resources[key.Value] as Style;
                        ToolTipService.SetToolTip(button, key.Value);
                        button.Click += (sender, args) =>
                        {
                            string styleName = ToolTipService.GetToolTip(sender as Button) as string;
                            DataPackage clipboardData = new DataPackage();
                            clipboardData.SetText(styleName);
                            Clipboard.SetContent(clipboardData);
                        };
                        AppBarButtonListView.Items.Add(button);
                    }
                }
            }
        }
示例#9
0
 // копирование ссылки
 private void CopyPageLink(object sender, object e)
 {
     Windows.ApplicationModel.DataTransfer.DataPackage dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage();
     dataPackage.SetText(App.Settings.current_site + ((sender as AppBarButton).DataContext as string));
     Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
     ShowMessage("Сopied!");
 }
示例#10
0
 private void CopyLink()
 {
     DataPackage dataPackage = new DataPackage();
     dataPackage.RequestedOperation = DataPackageOperation.Copy;
     dataPackage.SetText(GetLinkToShare());
     Clipboard.SetContent(dataPackage);
 }
        void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            OutputText.Text = "";
            OutputResourceMapKeys.Text = "";
            OutputHtml.NavigateToString("<HTML></HTML>");

            // Set the content to DataPackage as html format
            string htmlFormat = HtmlFormatHelper.CreateHtmlFormat(this.htmlFragment);
            var dataPackage = new DataPackage();
            dataPackage.SetHtmlFormat(htmlFormat);

            // Set the content to DataPackage as (plain) text format
            string plainText = HtmlUtilities.ConvertToText(this.htmlFragment);
            dataPackage.SetText(plainText);

            // Populate resourceMap with StreamReference objects corresponding to local image files embedded in HTML
            var imgUri = new Uri(imgSrc);
            var imgRef = RandomAccessStreamReference.CreateFromUri(imgUri);
            dataPackage.ResourceMap[imgSrc] = imgRef;

            try
            {
                // Set the DataPackage to clipboard.
                Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
                OutputText.Text = "Text and HTML formats have been copied to clipboard. ";
            }
            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);
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DataPackage dataPackage = new DataPackage();
            dataPackage.RequestedOperation = DataPackageOperation.Copy;
            dataPackage.SetText("クリップボードに文字列を渡します!!");

            Clipboard.SetContent(dataPackage);
        }
示例#13
0
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     var dataPackage = new DataPackage();
     dataPackage.SetText(Result);
     Clipboard.SetContent(dataPackage);
     MessageHelper.ShowToastNotification("StoreLogo.png", "已复制到粘贴板!", NotificationAudioNames.Default);
     args.Cancel = true;
 }
示例#14
0
		private void Copybutton_Tapped(object sender, TappedRoutedEventArgs e)
		{
			var dataPackage = new DataPackage();			
			string plainText = HtmlUtilities.ConvertToText(output.Text);
			dataPackage.SetText(plainText);

			Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
        }
示例#15
0
 private void btn_Share_Click(object sender, RoutedEventArgs e)
 {
     Windows.ApplicationModel.DataTransfer.DataPackage pack = new Windows.ApplicationModel.DataTransfer.DataPackage();
     pack.SetText(string.Format("我正在哔哩哔哩上看《{0}》\r\n地址:http://www.bilibili.com/video/av{1}", (this.DataContext as VideoInfoModels).title, _aid));
     Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(pack); // 保存 DataPackage 对象到剪切板
     Windows.ApplicationModel.DataTransfer.Clipboard.Flush();
     messShow.Show("已将内容复制到剪切板", 3000);
 }
示例#16
0
        private void CopyToClipBoard(object sender, RoutedEventArgs e)
        {
            var content = new DataPackage();
            content.SetUri(new Uri(textboxLink.Text));
            content.SetText(textboxLink.Text);

            Clipboard.SetContent(content);
        }
示例#17
0
 private static void TextBlock_Tapped1(object sender, TappedRoutedEventArgs e)
 {
     // Use this to copy field value to Clipboard, if using TextBlock
     var textb = sender as TextBlock;
     var dataPackage = new DataPackage();
     dataPackage.SetText(textb.Text);
     Clipboard.SetContent(dataPackage);
 }
示例#18
0
 private void cd_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Windows.ApplicationModel.DataTransfer.DataPackage pack = new Windows.ApplicationModel.DataTransfer.DataPackage();
     pack.SetText((sender.DataContext as LiveVideoModel).item.share_url);
     Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(pack); // 保存 DataPackage 对象到剪切板
     Windows.ApplicationModel.DataTransfer.Clipboard.Flush();
     messShow.Show("已将内容复制到剪切板", 3000);
 }
示例#19
0
 private void Share_Click(object sender, RoutedEventArgs e)
 {
     Windows.ApplicationModel.DataTransfer.DataPackage pack = new Windows.ApplicationModel.DataTransfer.DataPackage();
     pack.SetText(string.Format("我正在BiliBili追{0},一起来看吧\r\n地址:http://bangumi.bilibili.com/anime/{1}", txt_Name.Text, banID));
     Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(pack); // 保存 DataPackage 对象到剪切板
     Windows.ApplicationModel.DataTransfer.Clipboard.Flush();
     messShow.Show("已将内容复制到剪切板", 3000);
 }
示例#20
0
        private void menu_copy_Click(object sender, RoutedEventArgs e)
        {
            DataPackage pack = new Windows.ApplicationModel.DataTransfer.DataPackage();

            pack.SetText(webView.Source.AbsoluteUri);
            Clipboard.SetContent(pack); // 保存 DataPackage 对象到剪切板
            Clipboard.Flush();
        }
示例#21
0
 private async void CopyLinkToClipboardCommand(object sender, RoutedEventArgs e)
 {
     FlyoutMore.Hide();
     var dp = new DataPackage();
     dp.SetText($"http://www.myanimelist.net/{(ViewModel.AnimeMode ? "anime" : "manga")}/{ViewModel.Id}");
     Clipboard.SetContent(dp);
     FlyoutMore.Hide();
     UWPUtilities.GiveStatusBarFeedback("Copied to clipboard...");
 }
 private void CharButton_Click(object sender, RoutedEventArgs e)
 {
     if (FontChar != null)
     {
         var dataPackage = new DataPackage();
         dataPackage.SetText(FontChar.Char.ToString());
         Clipboard.SetContent(dataPackage);
     }
 }
示例#23
0
 /// <summary>
 /// 复制链接
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void ShareByCopyUriAppBarButton_Tapped(object sender, TappedRoutedEventArgs e)
 {
     DataPackage dataPackage = new DataPackage();
     dataPackage.SetText(this._url);
     Clipboard.SetContent(dataPackage);
     MessageDialog messageDialog = new MessageDialog("复制成功");
     IUICommand uiCommand = await messageDialog.ShowAsync();
     this.Hide();
 }
示例#24
0
 public static void CopyToClipBoard(string str)
 {
     var dp = new DataPackage
     {
         RequestedOperation = DataPackageOperation.Copy,
     };
     dp.SetText(str);
     Clipboard.SetContent(dp);
 }
示例#25
0
        internal void SetText(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            DT.DataPackage dataPackage = new DT.DataPackage();
            dataPackage.SetText(text);

            DT.Clipboard.SetContent(dataPackage);
        }
示例#26
0
		partial void HandleShareRequested(string shareLink)
		{
			var dataPackage = new DataPackage();
			dataPackage.SetText(shareLink);
            dataPackage.SetWebLink(new Uri(shareLink));
			Clipboard.SetContent(dataPackage);

			var notificationService = SimpleIoc.Default.GetInstance<NotificationService>();
			notificationService.ShowToast("File shared", "A link has been copied to the clipboard", "Assets/Logo.scale-100.png");

			this.Complete();
		}
示例#27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="text"></param>
 public async Task SetText(string text)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         () =>
         {
             var package = new DataPackage();
             package.RequestedOperation = DataPackageOperation.Copy;
             package.SetText(text);
             Clipboard.SetContent(package);
         });
 }
示例#28
0
        private void CopyBtn_Click(object sender, RoutedEventArgs e)
        {
            var input = this.MainTxtbx.Text.ToString();

            if (input != null && this.engine != null)
            {
                DataPackage content = new DataPackage();
                content.SetText(input);

                Clipboard.SetContent(content);
            }
        }
示例#29
0
        public static DataPackageView GetContent()
        {
            var dataPackage = new DataPackage();

            var clipText = UIPasteboard.General.String;

            if (clipText != null)
            {
                dataPackage.SetText(clipText);
            }

            return(dataPackage.GetView());
        }
		private void copyToClipboardReceiver(CopyToClipboardMessage message)
		{
			DataPackage package = new DataPackage();
			package.SetText(message.Content);
			Clipboard.SetContent(package);
			if (!String.IsNullOrWhiteSpace(message.SuccessMessage))
			{
				dialogMessageReceiver(new DialogMessage
				{
					Description = message.SuccessMessage
				});
			}
		}
示例#31
0
        public Task CopyToClipboard(string textToCopy)
        {
            Task retVal = Task.Delay(0);
            try
            {
                var dataPackage = new DataPackage();
                dataPackage.SetText(textToCopy);
                Clipboard.SetContent(dataPackage);

                return ClearClipboard();
            }
            catch { }
           return retVal;
        }
示例#32
0
        private void ExecuteCopyCommand()
        {
            StringBuilder sb = new StringBuilder();
            foreach (string logEntry in Logger.LogMessages)
            {
                sb.Append(logEntry);
                sb.Append("\r\n");
            }

            DataPackage dataPackage = new DataPackage();
            dataPackage.SetText(sb.ToString());

            Clipboard.SetContent(dataPackage);
        }
示例#33
0
        private static void CopyText(string text)
        {
            var dataPackage = new DataPackage();
            dataPackage.SetText(text);

            try
            {
                Clipboard.SetContent(dataPackage);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
示例#34
0
        async void Lipsum_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            e.Handled = true;
            TextBox t = (TextBox)sender;

            PopupMenu p = new PopupMenu();
            p.Commands.Add(new UICommand("Cut", null, 0));
            p.Commands.Add(new UICommand("Copy", null, 1));
            p.Commands.Add(new UICommand("Paste", null, 2));
            p.Commands.Add(new UICommand("Select All", null, 3));
            p.Commands.Add(new UICommandSeparator());
            p.Commands.Add(new UICommand("Delete", null, 4));

            var selectedCommand = await p.ShowForSelectionAsync(GetTextBoxRect(t));

            if (selectedCommand != null)
            {
                String text;
                DataPackage d;
                
                switch ((int)selectedCommand.Id)
                {
                    case 0: //CUT
                        text = t.SelectedText;
                        t.SelectedText = "";
                        d = new DataPackage();
                        d.SetText(text);
                        Clipboard.SetContent(d);
                        break;
                    case 1: //COPY
                        text = t.SelectedText;
                        d = new DataPackage();
                        d.SetText(text);
                        Clipboard.SetContent(d);
                        break;
                    case 2: //PASTE
                        text = await Clipboard.GetContent().GetTextAsync();
                        t.SelectedText = text;
                        break;
                    case 3: //SELECT ALL
                        t.SelectAll();
                        break;
                    case 4: //DELETE
                        t.SelectedText = "";
                        break;
                }
            }
        }
示例#35
0
 // Function to make an api call. Takes the access_token and the api to call as arguments.
 public async Task<string> apiCall(String access_token, String href)
 {
     HttpClient httpClient = new HttpClient();
     Debug.WriteLine("Created httpclient. " + href);
     httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", access_token);
     httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json"));
     Debug.WriteLine("Awaiting http request after this");
     var httpResponseMessage = await httpClient.GetAsync(new Uri(href));
     Debug.WriteLine("Done awaiting http request");
     string apiResponse = await httpResponseMessage.Content.ReadAsStringAsync();
     Debug.WriteLine("Done reading response as string : " + apiResponse);
 
     var dataPackage = new DataPackage();
     dataPackage.SetText(apiResponse);
     Clipboard.SetContent(dataPackage);
     return apiResponse;
 }
        private void ButtonSendTileNotification_Click(object sender, RoutedEventArgs e)
        {
            TileBindingContentAdaptive bindingContent = new TileBindingContentAdaptive()
            {
            Children =
            {
            GenerateEmailGroup("Jennifer Parker", "Photos from our trip"),
            GenerateEmailGroup("Steve Bosniak", "Want to go out for dinner after Build tonight?")
            }
            };

            TileBinding binding = new TileBinding()
            {
            Content = bindingContent
            };

            TileContent content = new TileContent()
            {
            Visual = new TileVisual()
            {
            TileMedium = binding
            }
            };

            DataPackage dp = new DataPackage();
            dp.SetText(content.GetContent());
            Clipboard.SetContent(dp);
            return;

            string xmlAsString = content.GetContent();
            TileNotification notification = new TileNotification(content.GetXml());

            content.Visual.TileMedium = new TileBinding()
            {
                Branding = TileBranding.Logo,

                Content = new TileBindingContentAdaptive()
            };

            ComboBox comboBox = new ComboBox();
            //var tileContent = NotificationsExtensions.GenerateTileContent();
            //TileNotification notif = new TileNotification(null);
            //ITileSquareText01 tileContent = TileContentFactory.CreateTileSquareText01();
        }
示例#37
0
        private async Task CopyLink(File file)
        {
            this.IsLoading = true;
            try
            {
                var link = await this.client.GetPublicFileLinkAsync(file.FileId, null);
                var dataPackage = new DataPackage();
                dataPackage.SetText(link);
                dataPackage.SetWebLink(new Uri(link));
                Clipboard.SetContent(dataPackage);

                var notificationService = SimpleIoc.Default.GetInstance<NotificationService>();
                notificationService.ShowToast("File(s) shared", "A link has been copied to the clipboard", "Assets/Logo.scale-100.png");
            }
            finally
            {
                this.IsLoading = false;
            }
        }
示例#38
0
        private static DataPackageView GetFromNative(NSPasteboard pasteboard)
        {
            if (pasteboard is null)
            {
                throw new ArgumentException(nameof(pasteboard));
            }

            var dataPackage = new DataPackage();

            // Extract all the standard data format information from the pasteboard items.
            // Each format can only be used once; therefore, generally the last occurrence of the format will be the one used.
            foreach (NSPasteboardItem item in pasteboard.PasteboardItems)
            {
                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeTIFF) ||
                    item.Types.Contains(NSPasteboard.NSPasteboardTypePNG))
                {
                    // Images may be very large, we never want to load them until they are needed.
                    // Therefore, create a data provider used to asynchronously fetch the image.
                    dataPackage.SetDataProvider(
                        StandardDataFormats.Bitmap,
                        async cancellationToken =>
                    {
                        NSImage?image = null;

                        /* Some apps, including Photos, don't appear to put image data in the pasteboard.
                         * Instead, the image URL is provided although the type indicates it is an image.
                         *
                         * To get around this an image is read as follows:
                         *   (1) If the pasteboard contains an image type then:
                         *   (2) Attempt to read the image as an object (NSImage).
                         *       This may fail as some tested apps provide a URL although declare an image (Photos).
                         *       With other apps (such as web browsers) an image will be read correctly here.
                         *   (3) If reading as an NSImage object fails, attempt to read the image from a file URL (local images)
                         *   (4) If reading from a file URL fails, attempt to read the image from a URL (remote images)
                         *
                         * Reading as an NSImage object follows the docs here:
                         *   https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/copy-paste#add-an-nsdocument
                         */

                        var classArray = new Class[] { new Class("NSImage") };
                        if (pasteboard.CanReadObjectForClasses(classArray, null))
                        {
                            NSObject[] objects = pasteboard.ReadObjectsForClasses(classArray, null);

                            if (objects.Length > 0)
                            {
                                // Only use the first image found
                                image = objects[0] as NSImage;
                            }
                        }

                        // In order to get here the pasteboard must have declared it had image types.
                        // However, if image is null, no objects were found and the image is likely a URL instead.
                        if (image == null &&
                            item.Types.Contains(NSPasteboard.NSPasteboardTypeFileUrl))
                        {
                            var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeFileUrl);
                            image   = new NSImage(new NSUrl(url));
                        }

                        if (image == null &&
                            item.Types.Contains(NSPasteboard.NSPasteboardTypeUrl))
                        {
                            var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeUrl);
                            image   = new NSImage(new NSUrl(url));
                        }

                        if (image != null)
                        {
                            // Thanks to: https://stackoverflow.com/questions/13305028/monomac-best-way-to-convert-bitmap-to-nsimage/13355747
                            using (var imageData = image.AsTiff())
                            {
                                var imgRep = NSBitmapImageRep.ImageRepFromData(imageData !) as NSBitmapImageRep;
                                var data   = imgRep !.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png, null);

                                return(new RandomAccessStreamReference(async ct =>
                                {
                                    return data.AsStream().AsRandomAccessStream().TrySetContentType("image/png");
                                }));
                            }
                        }
                        else
                        {
                            // Return an empty image
                            return(new RandomAccessStreamReference(async ct =>
                            {
                                var stream = new MemoryStream();
                                stream.Position = 0;

                                return stream.AsRandomAccessStream().TrySetContentType("image/png");
                            }));
                        }
                    });
                }

                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeHTML))
                {
                    var html = item.GetStringForType(NSPasteboard.NSPasteboardTypeHTML);
                    if (html != null)
                    {
                        dataPackage.SetHtmlFormat(html);
                    }
                }

                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeRTF))
                {
                    var rtf = item.GetStringForType(NSPasteboard.NSPasteboardTypeRTF);
                    if (rtf != null)
                    {
                        dataPackage.SetRtf(rtf);
                    }
                }

                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeFileUrl))
                {
                    // Drag and drop will use temporary URLs similar to: file:///.file/id=1234567.1234567
                    var tempFileUrl = item.GetStringForType(NSPasteboard.NSPasteboardTypeFileUrl);

                    // Files may be very large, we never want to load them until they are needed.
                    // Therefore, create a data provider used to asynchronously fetch the file.
                    dataPackage.SetDataProvider(
                        StandardDataFormats.StorageItems,
                        async cancellationToken =>
                    {
                        // Convert from a temp Url (see above example) into an absolute file path
                        var fileUrl = new NSUrl(tempFileUrl);
                        var file    = await StorageFile.GetFileFromPathAsync(fileUrl.FilePathUrl.AbsoluteString);

                        var storageItems = new List <IStorageItem>();
                        storageItems.Add(file);

                        return(storageItems.AsReadOnly());
                    });
                }

                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeString))
                {
                    var text = item.GetStringForType(NSPasteboard.NSPasteboardTypeString);
                    if (text != null)
                    {
                        dataPackage.SetText(text);
                    }
                }

                if (item.Types.Contains(NSPasteboard.NSPasteboardTypeUrl))
                {
                    var url = item.GetStringForType(NSPasteboard.NSPasteboardTypeUrl);
                    if (url != null)
                    {
                        DataPackage.SeparateUri(
                            url,
                            out string?webLink,
                            out string?applicationLink);

                        if (webLink != null)
                        {
                            dataPackage.SetWebLink(new Uri(webLink));
                        }

                        if (applicationLink != null)
                        {
                            dataPackage.SetApplicationLink(new Uri(applicationLink));
                        }

                        // Deprecated but still added for compatibility
                        dataPackage.SetUri(new Uri(url));
                    }
                }
            }

            return(dataPackage.GetView());
        }
示例#39
0
        public static DataPackageView GetContent()
        {
            var dataPackage = new DataPackage();

            var manager = ContextHelper.Current.GetSystemService(Context.ClipboardService) as ClipboardManager;

            if (manager is null)
            {
                return(dataPackage.GetView());
            }

            var clipData = manager.PrimaryClip;

            Uri /* ? */    clipApplicationLink = null;
            string /* ? */ clipHtml            = null;
            string /* ? */ clipText            = null;
            Uri /* ? */    clipUri             = null;
            Uri /* ? */    clipWebLink         = null;

            // Extract all the standard data format information from the clipboard.
            // Each format can only be used once; therefore, the last occurrence of the format will be the one used.
            if (clipData != null)
            {
                for (int itemIndex = 0; itemIndex < clipData.ItemCount; itemIndex++)
                {
                    var item = clipData.GetItemAt(itemIndex);

                    if (item != null)
                    {
                        var itemText = item.Text;
                        if (itemText != null)
                        {
                            clipText = itemText;
                        }

                        var itemUriStr = item.Uri?.ToString();
                        if (itemUriStr != null)
                        {
                            DataPackage.SeparateUri(
                                itemUriStr,
                                out string webLink,
                                out string applicationLink);

                            clipWebLink         = webLink != null ? new Uri(webLink) : null;
                            clipApplicationLink = applicationLink != null ? new Uri(applicationLink) : null;
                            clipUri             = new Uri(itemUriStr);                             // Deprecated but still added for compatibility
                        }

                        var itemHtml = item.HtmlText;
                        if (itemHtml != null)
                        {
                            clipHtml = itemHtml;
                        }
                    }
                }
            }

            // Add standard data formats to the data package.
            // This can be done synchronously on Android since the data is already available from above.
            if (clipApplicationLink != null)
            {
                dataPackage.SetApplicationLink(clipApplicationLink);
            }

            if (clipHtml != null)
            {
                dataPackage.SetHtmlFormat(clipHtml);
            }

            if (clipText != null)
            {
                dataPackage.SetText(clipText);
            }

            if (clipUri != null)
            {
                dataPackage.SetUri(clipUri);
            }

            if (clipWebLink != null)
            {
                dataPackage.SetWebLink(clipWebLink);
            }

            return(dataPackage.GetView());
        }
示例#40
0
        public static DataPackageView GetContent()
        {
            var dataPackage = new DataPackage();

            var manager = ContextHelper.Current.GetSystemService(Context.ClipboardService) as ClipboardManager;

            if (manager is null)
            {
                return(dataPackage.GetView());
            }

            var clipData = manager.PrimaryClip;

            Uri /* ? */    clipApplicationLink = null;
            string /* ? */ clipHtml            = null;
            string /* ? */ clipText            = null;
            Uri /* ? */    clipUri             = null;
            Uri /* ? */    clipWebLink         = null;

            // Extract all the standard data format information from the clipboard.
            // Each format can only be used once; therefore, the last occurrence of the format will be the one used.
            if (clipData != null)
            {
                for (int itemIndex = 0; itemIndex < clipData.ItemCount; itemIndex++)
                {
                    var item = clipData.GetItemAt(itemIndex);

                    if (item != null)
                    {
                        var itemText = item.Text;
                        if (itemText != null)
                        {
                            clipText = itemText;
                        }

                        // An Android Uri must be specially mapped for UWP as the UWP's direct equivalent
                        // standard data format 'Uri' is deprecated.
                        //
                        // 1. WebLink is used if the URI has a scheme of http or https
                        // 2. ApplicationLink is used if not #1
                        //
                        // For full compatibility, Uri is still populated regardless of #1 or #2.
                        var itemUri    = item.Uri;
                        var itemUriStr = itemUri?.ToString();
                        if (itemUriStr != null)
                        {
                            if (itemUriStr.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ||
                                itemUriStr.StartsWith("https", StringComparison.InvariantCultureIgnoreCase))
                            {
                                clipWebLink = new Uri(itemUriStr);
                            }
                            else
                            {
                                clipApplicationLink = new Uri(itemUriStr);
                            }

                            // Deprecated but added for compatibility
                            clipUri = new Uri(itemUriStr);
                        }

                        var itemHtml = item.HtmlText;
                        if (itemText != null)
                        {
                            clipHtml = itemHtml;
                        }
                    }
                }
            }

            // Add standard data formats to the data package.
            // This can be done synchronously on Android since the data is already available from above.
            if (clipApplicationLink != null)
            {
                dataPackage.SetApplicationLink(clipApplicationLink);
            }

            if (clipHtml != null)
            {
                dataPackage.SetHtmlFormat(clipHtml);
            }

            if (clipText != null)
            {
                dataPackage.SetText(clipText);
            }

            if (clipUri != null)
            {
                dataPackage.SetUri(clipUri);
            }

            if (clipWebLink != null)
            {
                dataPackage.SetWebLink(clipWebLink);
            }

            return(dataPackage.GetView());
        }