Share via


Clipboard.ContentChanged Événement

Définition

Se produit lorsque les données stockées dans le Presse-papiers changent.

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

Type d'événement

Exemples

L’exemple suivant montre comment suivre les modifications apportées au Presse-papiers. Le premier extrait de code inscrit un gestionnaire pour l’événement ContentChanged. Le deuxième extrait de code montre le gestionnaire d’événements, qui affiche le contenu du texte du Presse-papiers dans un contrôle 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;
    }
}

Remarques

Cet événement est utile dans les situations où votre application contient une logique qui varie en fonction du contenu du Presse-papiers. Par exemple, votre application peut inclure un bouton Coller , qui est désactivé, sauf si le Presse-papiers contient du contenu.

S’applique à