DataTransferManager.GetForCurrentView Method

Definition

Returns the DataTransferManager object associated with the current window.

public:
 static DataTransferManager ^ GetForCurrentView();
 static DataTransferManager GetForCurrentView();
public static DataTransferManager GetForCurrentView();
function getForCurrentView()
Public Shared Function GetForCurrentView () As DataTransferManager

Returns

DataTransferManager

The DataTransferManager object associated with the current window.

Examples

This example calls the GetForCurrentView method to get the DataTransferManager object associated with the active window for the app.

//To see this code in action, add a call to ShareSourceLoad to your constructor or other
//initializing function.
private void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share Text Example";
    request.Data.Properties.Description = "An example of how to share text.";
    request.Data.SetText("Hello World!");
}

Remarks

Each window has a DataTransferManager object associated with it. When sharing content, you use the GetForCurrentView method to get the DataTransferManager object that is associated with the active window. After you have the appropriate DataTransferManager object, you can add an event listener to it to handle the DataRequested event, which the system fires when a share operation is initiated. Your app uses the DataRequest object returned with this event to set the data that the user wants to share with a target app.

Applies to