DataTransferManager.GetForCurrentView DataTransferManager.GetForCurrentView DataTransferManager.GetForCurrentView DataTransferManager.GetForCurrentView DataTransferManager.GetForCurrentView Method


Returns the DataTransferManager object associated with the current window.

public : static DataTransferManager GetForCurrentView()
static DataTransferManager GetForCurrentView() const;
public static DataTransferManager GetForCurrentView()
Public Shared Function GetForCurrentView() As DataTransferManager
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();



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!");
function registerForShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", shareTextHandler);

function shareTextHandler(e) {
    var request = e.request; = "Share Text Example"; = "A demonstration that shows how to share.";"Hello World!");


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.