Search code examples
javascriptclasswinapiuwpwindows-store-apps

UWP: DataPackageView Bug


The Docs for the Clipboard Class state, that the getContent() Method returns a DataPackageView object. So far so good.

The following works:

var containsString = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)

containsString equals true.

The following does not work:

var text = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().getTextAsync();
var text = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().getTextAsync(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text);
var text = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().getHtmlFormatAsync();
var text = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().getDataAsync(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text);

Each methods are listed in the above linked Doc for DataPackageView, all returning an empty object after checking contains(...).

This also does not work:

var results = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().requestAccessAsync();
var results = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().requestAccessAsync(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text);
var results = Windows.ApplicationModel.DataTransfer.Clipboard.getContent().unlockAndAssumeEnterpriseIdentity();

... all returning nothing.

Is that because these methods are asynchronous? Do I need a timeout?

I've literally tried everything. What am I doing wrong, or is this this a bug with the getContent() method or the DataPackageView?


Solution

  • in the first sample you are not calling an async method. In all the other cases you do. i don't have visual studio right here so cant try it out but it should like something like this:

    Windows.ApplicationModel.DataTransfer.Clipboard.getContent().getTextAsync().then(function(result){
    // result should be the text you are expecting
    });