DataTransferManager.DataRequested DataTransferManager.DataRequested DataTransferManager.DataRequested DataTransferManager.DataRequested DataTransferManager.DataRequested Event

Definition

Occurs when a share operation starts.

public : event TypedEventHandler DataRequested<DataTransferManager, DataRequestedEventArgs>
// Register
event_token DataRequested(TypedEventHandler<DataTransferManager, DataRequestedEventArgs> const& handler) const;

// Revoke with event_token
void DataRequested(event_token const& cookie) const;

// Revoke with event_revoker
DataRequested_revoker DataRequested(auto_revoker_t, TypedEventHandler<DataTransferManager, DataRequestedEventArgs> const& handler) const;
public event TypedEventHandler DataRequested<DataTransferManager, DataRequestedEventArgs>
Public Event TypedEventHandler DataRequested(Of DataTransferManager, DataRequestedEventArgs)
function onDataRequested(eventArgs){/* Your code */}


dataTransferManager.addEventListener("dataRequested", onDataRequested);
dataTransferManager.removeEventListener("dataRequested", onDataRequested);

Examples

This example uses an inline function to handle a datarequested event.

//To see this code in action, add a call to ShareSouceLoad 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;
    request.data.properties.title = "Share Text Example";
    request.data.properties.description = "A demonstration that shows how to share.";
    request.data.setText("Hello World!");
}

Remarks

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. To handle this event, you need to add an event listener to the DataTransferManager object for the active window. You can get this object through the GetForCurrentView method.

When handling a datarequested event, the most important property you need to be aware of is its request property. This property contains a DataRequest object. Your app uses this object to provide the data that the user wants to share with a selected target app.