Laxmi
Laxmi

Reputation: 93

How can we copy-paste text and image both from clipboard in uwp C#?

I want to paste a note with the combination of text and image in my chat compose box in the same sequence. I am using dataPackageView to check clipboard content

For Example - I need to copy paste a note from a Microsoft note

enter image description here

DataPackageView dataPackageView = Clipboard.GetContent();
if (dataPackageView.Contains(StandardDataFormats.Bitmap))
{         
  var img = await dataPackageView.GetBitmapAsync();
}
else if(dataPackageView.Contains(StandardDataFormats.Text)
{                 
  string text = await dataPackageView.GetTextAsync();
}

Upvotes: 0

Views: 412

Answers (1)

dear_vv
dear_vv

Reputation: 2358

I have copied a note(image+text) to Clipboard, then I checked the format of the content with DataPackageView.Contains() method, I can’t find any format to correspond it.

So you need to create a html string contains the text and the image, then use Clipboard.SetContent(DataPackage) method to add content to Clipboard with specified html format, then you could use DataPackageView.GetHtmlFormatAsync method to get content, finally you could use webView control to show its content. Please refer to this sample to know the detailed code.

Upvotes: 1

Related Questions