private async void Button_Click(object sender, RoutedEventArgs e) { Windows.ApplicationModel.DataTransfer.DataPackageView content = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent(); Windows.Foundation.IAsyncOperation <string> getTextOperation = content.GetTextAsync(); string s = await getTextOperation; this.clipboardResultTextBox.Text = s; }
private static string GetClipBoardText() { Windows.ApplicationModel.DataTransfer.DataPackageView clipBoard = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent(); Task <string> task = clipBoard.GetTextAsync().AsTask(); try { task.RunSynchronously(); } catch (InvalidOperationException) { } return(task.Result); }
private async void Paste_Invoked(Windows.UI.Xaml.Input.KeyboardAccelerator sender, Windows.UI.Xaml.Input.KeyboardAcceleratorInvokedEventArgs args) { Windows.ApplicationModel.DataTransfer.DataPackageView dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent(); if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text)) { string newText = await dataPackageView.GetTextAsync(); // Modify the internal text store. _text = _text.Substring(0, _selection.StartCaretPosition) + newText + _text.Substring(Math.Min(_text.Length, _selection.EndCaretPosition)); // You can set the proper font or direction for the updated text based on the language by checking // args.InputLanguage. We will not do that in this sample. // Modify the current selection. _selection.StartCaretPosition = _selection.EndCaretPosition += newText.Length; // Update the selection of the edit context. There is no need to notify the system // because the system itself changed the selection. SetSelectionAndNotify(_selection); } }