Clipboard.ContentChanged 事件

定義

發生于儲存在剪貼簿中的資料變更時。

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

事件類型

範例

下列範例示範如何追蹤剪貼 簿的變更。 第一個程式碼片段會註冊 ContentChanged 事件的處理常式。 第二個程式碼片段會顯示事件處理常式,它會在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;
    }
}

備註

當您的應用程式包含視剪貼簿內容而有所不同的邏輯時,此事件會很有説明。 例如,您的應用程式可能包含 [貼上 ] 按鈕,除非剪貼簿包含內容,否則會停用。

適用於