Dela via


DataTransferManager.DataRequested Event

Definition

Occurs when a share operation starts.

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

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

// Revoke with event_revoker
DataTransferManager::DataRequested_revoker DataRequested(auto_revoke_t, TypedEventHandler<DataTransferManager, DataRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<DataTransferManager,DataRequestedEventArgs> DataRequested;
function onDataRequested(eventArgs) { /* Your code */ }
dataTransferManager.addEventListener("datarequested", onDataRequested);
dataTransferManager.removeEventListener("datarequested", onDataRequested);
- or -
dataTransferManager.ondatarequested = onDataRequested;
Public Custom Event DataRequested As TypedEventHandler(Of DataTransferManager, DataRequestedEventArgs) 

Event Type

Examples

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

//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

This event is fired when 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.

Applies to