Clipboard Clipboard Clipboard Clipboard Clipboard Class

Definition

Gets and sets information from the clipboard object.

public : static class Clipboard
static struct winrt::Windows::ApplicationModel::DataTransfer::Clipboard
public static class Clipboard
Public Shared Class Clipboard
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following sample shows how to track changes to the Clipboard. If the Clipboard has text, the code adds the text to an HTML page.

Windows.ApplicationModel.DataTransfer.Clipboard.addEventListener("contentchanged", function (event) {
    var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent();
    if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
        dataPackageView.getTextAsync().then(function (text) {
            // To output the text from this example, you need an HTML element
            // with an id of "output".
            document.getElementById("output").innerText = "Clipboard now contains: " + text;
        });
    }
});

Remarks

Because the Clipboard class is a static class, you don't need to create an instance of it to access its methods.

Note

This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

You can only access the clipboard when the calling application is in focus on the UI thread (e.g., when it's CoreWindow is active). Use the CoreWindow.Activated event to track the state of the calling app.

Version history

Windows version SDK version Value added
1809 17763 ClearHistory
1809 17763 DeleteItemFromHistory
1809 17763 GetHistoryItemsAsync
1809 17763 HistoryChanged
1809 17763 HistoryEnabledChanged
1809 17763 IsHistoryEnabled
1809 17763 IsRoamingEnabled
1809 17763 RoamingEnabledChanged
1809 17763 SetContentWithOptions
1809 17763 SetHistoryItemAsContent

Methods

Clear() Clear() Clear() Clear() Clear()

Removes all data from the Clipboard.

ClearHistory() ClearHistory() ClearHistory() ClearHistory() ClearHistory()

Clears the clipboard history.

DeleteItemFromHistory(ClipboardHistoryItem) DeleteItemFromHistory(ClipboardHistoryItem) DeleteItemFromHistory(ClipboardHistoryItem) DeleteItemFromHistory(ClipboardHistoryItem) DeleteItemFromHistory(ClipboardHistoryItem)

Deletes the specified item from the clipboard history.

Flush() Flush() Flush() Flush() Flush()

Adds the content to the Clipboard and releases the DataPackage object from the source app. This method allows the content to remain available after the application shuts down.

GetContent() GetContent() GetContent() GetContent() GetContent()

Gets the current content that is stored in the clipboard object.

GetHistoryItemsAsync() GetHistoryItemsAsync() GetHistoryItemsAsync() GetHistoryItemsAsync() GetHistoryItemsAsync()

Gets the list of items currently in the clipboard history.

IsHistoryEnabled() IsHistoryEnabled() IsHistoryEnabled() IsHistoryEnabled() IsHistoryEnabled()

Indicates whether clipboard history (that is, the ability to save multiple items to the clipboard) is enabled for the current user.

IsRoamingEnabled() IsRoamingEnabled() IsRoamingEnabled() IsRoamingEnabled() IsRoamingEnabled()

Indicates whether clipboard data is set to sync across devices for the current user.

SetContent(DataPackage) SetContent(DataPackage) SetContent(DataPackage) SetContent(DataPackage) SetContent(DataPackage)

Sets the current content that is stored in the clipboard object.

SetContentWithOptions(DataPackage, ClipboardContentOptions) SetContentWithOptions(DataPackage, ClipboardContentOptions) SetContentWithOptions(DataPackage, ClipboardContentOptions) SetContentWithOptions(DataPackage, ClipboardContentOptions) SetContentWithOptions(DataPackage, ClipboardContentOptions)

Sets the content that is stored in the clipboard object with options for the content.

SetHistoryItemAsContent(ClipboardHistoryItem) SetHistoryItemAsContent(ClipboardHistoryItem) SetHistoryItemAsContent(ClipboardHistoryItem) SetHistoryItemAsContent(ClipboardHistoryItem) SetHistoryItemAsContent(ClipboardHistoryItem)

Sets an item in the clipboard history as the current content for the clipboard.

Events

ContentChanged ContentChanged ContentChanged ContentChanged ContentChanged

Occurs when the data stored in the Clipboard changes.

HistoryChanged HistoryChanged HistoryChanged HistoryChanged HistoryChanged

Occurs when a new item is added to the clipboard history.

HistoryEnabledChanged HistoryEnabledChanged HistoryEnabledChanged HistoryEnabledChanged HistoryEnabledChanged

Occurs when the OS setting that controls whether clipboard history is enabled for the current user is changed.

RoamingEnabledChanged RoamingEnabledChanged RoamingEnabledChanged RoamingEnabledChanged RoamingEnabledChanged

Occurs when the OS setting that controls whether clipboard data is set to sync across devices for the current user is changed.

See also