DataRequestDeferral DataRequestDeferral DataRequestDeferral DataRequestDeferral Class

Enables you to exchange content with a target app asynchronously.

Syntax

Declaration

public sealed class DataRequestDeferralpublic sealed class DataRequestDeferralPublic NotInheritable Class DataRequestDeferral

Remarks

You get an instance of the DataRequestDeferral class when you call the GetDeferral() method of a DataPackage

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);
    });
}

Methods summary

Indicates that the content for an asynchronous share is ready for a target app, or that an error in the sharing operation occurred.

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

    Remarks

    Your app must call the complete method when its finished adding data to a DataPackage.

    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);
        });
    }
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll