Share via


FileSavePickerUI.TargetFileRequested Evento

Definizione

Viene generato quando l'utente esegue il commit di un file da salvare nella selezione file.

// Register
event_token TargetFileRequested(TypedEventHandler<FileSavePickerUI, TargetFileRequestedEventArgs const&> const& handler) const;

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

// Revoke with event_revoker
FileSavePickerUI::TargetFileRequested_revoker TargetFileRequested(auto_revoke_t, TypedEventHandler<FileSavePickerUI, TargetFileRequestedEventArgs const&> const& handler) const;
public event TypedEventHandler<FileSavePickerUI,TargetFileRequestedEventArgs> TargetFileRequested;
function onTargetFileRequested(eventArgs) { /* Your code */ }
fileSavePickerUI.addEventListener("targetfilerequested", onTargetFileRequested);
fileSavePickerUI.removeEventListener("targetfilerequested", onTargetFileRequested);
- or -
fileSavePickerUI.ontargetfilerequested = onTargetFileRequested;
Public Custom Event TargetFileRequested As TypedEventHandler(Of FileSavePickerUI, TargetFileRequestedEventArgs) 

Tipo evento

Esempio

L'esempio di selezione file illustra come rispondere a un gestore eventi TargetFileRequested.

// Event handler
private async void OnTargetFileRequested(FileSavePickerUI sender, TargetFileRequestedEventArgs e)
{
    // Respond to TargetFileRequested event on the background thread on which it was raised

    // Requesting a deferral allows the app to call another asynchronous method and complete the request at a later time
    var deferral = e.Request.GetDeferral();

    // Create file and assign to TargetFile property
    e.Request.TargetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(sender.FileName, CreationCollisionOption.GenerateUniqueName);

    // Complete the deferral to let the Picker know the request is finished
    deferral.Complete();
}

// Register for the event
fileSavePickerUI.TargetFileRequested += new TypedEventHandler<FileSavePickerUI, TargetFileRequestedEventArgs>(OnTargetFileRequested);

Nell'esempio e contiene un oggetto TargetFileRequestedEventArgs .

Commenti

Se l'app partecipa al contratto selezione salvataggio file e viene generato un evento TargetFileRequested, l'app deve creare un nuovo oggetto StorageFile che rappresenta il file che l'utente vuole salvare. Il nome di StorageFile creato deve corrispondere al nome del file specificato dalla proprietà FileName . StorageFile creato viene restituito all'app che ha chiamato la selezione file (l'app chiamante) in modo che l'app chiamante possa scrivere contenuto nel file. Altre informazioni sulla risposta a questo evento in targetFileRequestedEventArgs.

Nota

L'interfaccia utente della selezione file è disabilitata fino a quando l'app che fornisce non ha terminato di rispondere a questo evento.

Si applica a

Vedi anche