DataTransferManager DataTransferManager DataTransferManager DataTransferManager DataTransferManager Class

Definition

Programmatically initiates an exchange of content with other apps.

public : sealed class DataTransferManager : IDataTransferManager, IDataTransferManager2
struct winrt::Windows::ApplicationModel::DataTransfer::DataTransferManager : IDataTransferManager, IDataTransferManager2
public sealed class DataTransferManager : IDataTransferManager, IDataTransferManager2
Public NotInheritable Class DataTransferManager Implements IDataTransferManager, IDataTransferManager2
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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. In general, we recommend against using this method. Users expect to initiate share operations by using the Share charm— when you launch the operation programmatically, you can create an inconsistent user experience. We include the method because there are a few scenarios in which the user might not recognize opportunities to share. A good example is when the user achieves a high score in a game.

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.

Methods

GetForCurrentView() GetForCurrentView() GetForCurrentView() GetForCurrentView() GetForCurrentView()

Returns the DataTransferManager object associated with the current window.

IsSupported() IsSupported() IsSupported() IsSupported() IsSupported()

Returns true if the device supports sharing, false otherwise.

ShowShareUI() ShowShareUI() ShowShareUI() ShowShareUI() ShowShareUI()

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

ShowShareUI(ShareUIOptions) ShowShareUI(ShareUIOptions) ShowShareUI(ShareUIOptions) ShowShareUI(ShareUIOptions) ShowShareUI(ShareUIOptions)

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

Events

DataRequested DataRequested DataRequested DataRequested DataRequested

Occurs when a share operation starts.

ShareProvidersRequested ShareProvidersRequested ShareProvidersRequested ShareProvidersRequested 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 TargetApplicationChosen TargetApplicationChosen TargetApplicationChosen TargetApplicationChosen

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

See Also