Condividi tramite


Clipboard.ContentChanged Evento

Definizione

Si verifica quando i dati archiviati negli Appunti cambiano.

// Register
static event_token ContentChanged(EventHandler<IInspectable> const& handler) const;

// Revoke with event_token
static void ContentChanged(event_token const* cookie) const;

// Revoke with event_revoker
static Clipboard::ContentChanged_revoker ContentChanged(auto_revoke_t, EventHandler<IInspectable> const& handler) const;
public static event System.EventHandler<object> ContentChanged;
function onContentChanged(eventArgs) { /* Your code */ }
Windows.ApplicationModel.DataTransfer.Clipboard.addEventListener("contentchanged", onContentChanged);
Windows.ApplicationModel.DataTransfer.Clipboard.removeEventListener("contentchanged", onContentChanged);
- or -
Windows.ApplicationModel.DataTransfer.Clipboard.oncontentchanged = onContentChanged;
Public Shared Custom Event ContentChanged As EventHandler(Of Object) 

Tipo evento

Esempio

Nell'esempio seguente viene illustrato come tenere traccia delle modifiche apportate agli Appunti. Il primo frammento di codice registra un gestore per l'evento ContentChanged. Il secondo frammento di codice mostra il gestore eventi, che visualizza il contenuto di testo degli Appunti in un controllo TextBlock .

Clipboard.ContentChanged += new EventHandler<object>(this.TrackClipboardChanges_EventHandler);
private async void TrackClipboardChanges_EventHandler(object sender, object e)
{
    DataPackageView dataPackageView = Clipboard.GetContent();
    if (dataPackageView.Contains(StandardDataFormats.Text))
    {
        String text = await dataPackageView.GetTextAsync();

        // To output the text from this example, you need a TextBlock control
        // with a name of "TextOutput".
        TextOutput.Text = "Clipboard now contains: " + text;
    }
}

Commenti

Questo evento è utile nelle situazioni in cui l'app contiene la logica che varia a seconda del contenuto negli Appunti. Ad esempio, l'app potrebbe includere un pulsante Incolla , disabilitato a meno che gli Appunti non contengano contenuto.

Si applica a