Udostępnij za pośrednictwem


DataTransferManager Class

Definition

Programmatically initiates an exchange of content with other apps.

public ref class DataTransferManager sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class DataTransferManager final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DataTransferManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class DataTransferManager
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DataTransferManager
Public NotInheritable Class DataTransferManager
Inheritance
Object Platform::Object IInspectable DataTransferManager
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This example shows a typical way of using the DataTransferManager object.

function setupShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", function (e) {
        var request = e.request;
        request.data.properties.title = "Share Demonstration";
        request.data.setText("Hello World!");
    });
}

Remarks

The DataTransferManager class is a static class that you use to initiate sharing operations. To use the class, first call the GetForCurrentView method. This method returns the DataTransferManager object that is specific to the active window. Next, you need to add an event listener for the datarequested event to the object. This event is fired when a sharing operation starts— typically when the user taps the Share charm, although it is also fired if your app starts a share operation programmatically.

The DataTransferManager class includes a ShowShareUI method, which you can use to programmatically start a share operation.

The DataTransferManager class also has a TargetApplicationChosen event. Use this event when you want to capture what applications a user selects when sharing content from your app.

Note

This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Windows Phone 8

This API is supported in native apps only.

Version history

Windows version SDK version Value added
1607 14393 IsSupported
1703 15063 ShareProvidersRequested
1709 16299 ShowShareUI(ShareUIOptions)

Methods

GetForCurrentView()

Returns the DataTransferManager object associated with the current window.

IsSupported()

Returns true if the device supports sharing, false otherwise.

ShowShareUI()

Programmatically initiates the user interface for sharing content with another app.

This API is for Universal Windows Platform (UWP) apps. The alternative API to use for a desktop app is described in Display WinRT UI objects that depend on CoreWindow.

ShowShareUI(ShareUIOptions)

Programmatically initiates the user interface for sharing content with another app.

This API is for Universal Windows Platform (UWP) apps. The alternative API to use for a desktop app is described in Display WinRT UI objects that depend on CoreWindow.

Events

DataRequested

Occurs when a share operation starts.

ShareProvidersRequested

An event that is triggered when the share providers are requested. This is used as a callback and providers are added by subscribing to this event and calling ShareProvidersRequestedEventArgs.Providers.Add() in the event handler.

TargetApplicationChosen

Occurs when the user chooses a target app in the Share UI.

Applies to

See also