DataProviderRequest DataProviderRequest DataProviderRequest DataProviderRequest Class

An object of this type is passed to the DataProviderHandler delegate.

Syntax

Declaration

public sealed class DataProviderRequestpublic sealed class DataProviderRequestPublic NotInheritable Class DataProviderRequestpublic sealed class DataProviderRequest

Remarks

Use this object when you need to delay, or defer, a share for a few milliseconds. To learn more, check out How to delay sharing.

Examples

async void OnDeferredImageRequestedHandler(DataProviderRequest request)
{
    // Provide updated bitmap data using delayed rendering.
    if (this.imageStream != null)
    {
        DataProviderDeferral deferral = request.GetDeferral();
        InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();

        // Decode the image.
        BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(this.imageStream);

        // Re-encode the image at 50% width and height.
        BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
        imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
        imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
        await imageEncoder.FlushAsync();

        request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
        deferral.Complete();
    }
}
function onDeferredImageRequested(request) {
    try {
        if (imageFile) {
            // This is to make sure deferral works even in synchronous case
            var deferral = request.getDeferral();
            var imageStreamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
            request.setData(imageStreamRef);
            deferral.complete();
        }
    } catch (exc) {
        // Error handling goes here.
    }
}

Properties summary

Gets the deadline for finishing a delayed rendering operation. If execution goes beyond that deadline, the results of delayed rendering are ignored.

Specifies the format id.

Methods summary

Returns a DataProviderDeferral object.

Sets the content of the DataPackage to be shared with a target app.

Properties

  • Deadline
    Deadline
    Deadline
    Deadline

    Gets the deadline for finishing a delayed rendering operation. If execution goes beyond that deadline, the results of delayed rendering are ignored.

    public DateTime Deadline { get; }public DateTimeOffset Deadline { get; }Public ReadOnly Property Deadline As DateTimeOffsetpublic DateTime Deadline { get; }

    Property Value

  • FormatId
    FormatId
    FormatId
    FormatId

    Specifies the format id.

    public string FormatId { get; }public string FormatId { get; }Public ReadOnly Property FormatId As stringpublic string FormatId { get; }

    Property Value

Methods

  • GetDeferral()
    GetDeferral()
    GetDeferral()
    GetDeferral()

    Returns a DataProviderDeferral object.

    public DataProviderDeferral GetDeferral()public DataProviderDeferral GetDeferral()Public Function GetDeferral() As DataProviderDeferralpublic DataProviderDeferral GetDeferral()

    Returns

    Remarks

    To learn more, check out How to produce requested data asynchronously.

    Examples

    async void OnDeferredImageRequestedHandler(DataProviderRequest request)
    {
        // Provide updated bitmap data using delayed rendering.
        if (this.imageStream != null)
        {
            DataProviderDeferral deferral = request.GetDeferral();
            InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();
    
            // Decode the image.
            BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(this.imageStream);
    
            // Re-encode the image at 50% width and height.
            BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
            imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
            imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
            await imageEncoder.FlushAsync();
    
            request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
            deferral.Complete();
        }
    }
    
    function onDeferredImageRequested(request) {
        try {
            if (imageFile) {
                // This is to make sure deferral works even in synchronous case
                var deferral = request.getDeferral();
                var imageStreamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
                request.setData(imageStreamRef);
                deferral.complete();
            }
        } catch (exc) {
            // Error handling goes here.
        }
    }
    
  • SetData(Object)
    SetData(Object)
    SetData(Object)
    SetData(Object)

    Sets the content of the DataPackage to be shared with a target app.

    public void SetData(Object value)public void SetData(Object value)Public Function SetData(value As Object) As voidpublic void SetData(Object value)

    Parameters

    • value
      System.Object
      System.Object
      System.Object
      System.Object

      The object associated with a particular format in the DataPackage.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

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

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll