EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

DataPackage.SetDataProvider | setDataProvider method

Applies to Windows and Windows Phone

Sets a delegate to handle requests from the target app.

Syntax


dataPackage.setDataProvider(formatId, delayRenderer);

Parameters

formatId

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

Specifies the format of the data. We recommend that you set this value by using the StandardDataFormats class.

delayRenderer

Type: DataProviderHandler

A delegate that is responsible for processing requests from a target app.

Remarks

Use the SetDataProvider method when your app supports a specific format, but does not want to supply the data until the target app requests it. We encourage you to use this method if your app shares content that can require significant processing time; for example, sharing a selection of photos, videos, or files.

When you use this method, you need to specify a format and a function. You can specify the format by using the StandardDataFormats class, or you can use a string value for a custom format. The function must put data in the DataPackage by using a method like SetData.

The SetDataProvider method is different from the GetDeferral method of the DataRequest class. With GetDeferral, a source app can call a function that immediately puts the data in the DataPackage object. The SetDataProvider method is for more complex share operations where packaging the data to be shared is more time-intensive or resource-intensive.

Examples


var imageFile;
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
picker.pickSingleFileAsync().then(function (file) {
    logText("PickImage: Picker returned a file");
    imageFile = file;
});

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.
    }
}


function shareFiles() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", function (e) {
        var request = e.request;
        request.data.properties.title = "Share Files Example";
        request.data.properties.description = "A demonstration that shows how to share files.";
        request.data.properties.fileTypes.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
        request.data.setDataProvider(Windows.ApplicationModel.DataTransfer.StandardDataFormats.bitmap, onDeferredImageRequested);
    });
}



Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.ApplicationModel.DataTransfer
Windows::ApplicationModel::DataTransfer [C++]

Metadata

Windows.winmd

See also

DataPackage

 

 

Mostrar:
© 2014 Microsoft