DataRequestDeferral
DataRequestDeferral
DataRequestDeferral
DataRequestDeferral
Class
Definition
Enables you to exchange content with a target app asynchronously.
public : sealed class DataRequestDeferral : IDataRequestDeferralpublic sealed class DataRequestDeferral : IDataRequestDeferralPublic NotInheritable Class DataRequestDeferral Implements IDataRequestDeferral// You can use this class in JavaScript.
- Attributes
Windows 10 requirements
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
This example shows how to get a DataRequestDeferral object as part of sharing an image with a target app.
void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequestDeferral deferral = e.Request.GetDeferral();
e.Request.Data.Properties.Title = "Hello World!";
e.Request.Data.Properties.Description = "This example shows how to share files and images.";
if (this.dataPackageThumbnail != null)
{
e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
}
e.Request.Data.SetBitmap(imageStreamRef);
deferral.Complete();
}
function registerForShare() {
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
dataTransferManager.addEventListener("datarequested", shareImageHandler);
}
function shareImageHandler(e) {
var request = e.request;
request.data.properties.title = "Share Image Example";
request.data.properties.description = "A demonstration that shows how to share an image.";
var deferral = request.getDeferral();
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\smalllogo.png").then(function (thumbnailFile) {
request.data.properties.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(thumbnailFile);
return Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\logo.png");
}).done(function (imageFile) {
request.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile));
deferral.complete();
}, function (err) {
request.failWithDisplayText(err);
});
}
Remarks
You get an instance of the DataRequestDeferral class when you call the getDeferral method of a DataPackage.
Methods
Complete() Complete() Complete() Complete()
Indicates that the content for an asynchronous share is ready for a target app, or that an error in the sharing operation occurred.
public : void Complete()public void Complete()Public Function Complete() As void// You can use this method in JavaScript.
Examples
This example shows how to call the complete method after getting a DataRequestDeferral object.
void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequestDeferral deferral = e.Request.GetDeferral();
e.Request.Data.Properties.Title = "Hello World!";
e.Request.Data.Properties.Description = "This example shows how to share files and images.";
if (this.dataPackageThumbnail != null)
{
e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
}
e.Request.Data.SetBitmap(imageStreamRef);
deferral.Complete();
}
function registerForShare() {
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
dataTransferManager.addEventListener("datarequested", shareImageHandler);
}
function shareImageHandler(e) {
var request = e.request;
request.data.properties.title = "Share Image Example";
request.data.properties.description = "A demonstration that shows how to share an image.";
var deferral = request.getDeferral();
Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\smalllogo.png").then(function (thumbnailFile) {
request.data.properties.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(thumbnailFile);
return Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\logo.png");
}).done(function (imageFile) {
request.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile));
deferral.complete();
}, function (err) {
request.failWithDisplayText(err);
});
}
Remarks
Your app must call the complete method when its finished adding data to a DataPackage.