Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Clipboard class

Applies to Windows only

Gets and sets information from the clipboard object.

Syntax


var clipboard = Windows.ApplicationModel.DataTransfer.Clipboard;

Attributes

[DualApiPartition()]
[MarshalingBehavior(Standard)]
[Version(0x06020000)]

Members

The Clipboard class has these types of members:

Events

The Clipboard class has these events.

EventDescription
ContentChanged Occurs when the data stored in the Clipboard changes.

 

Methods

The Clipboard class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Clear Removes all data from the Clipboard.
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 Gets the current content that is stored in the clipboard object.
SetContent Sets the current content that is stored in the clipboard object.

 

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

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;
        });
    }
});


Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.DataTransfer
Windows::ApplicationModel::DataTransfer [C++]

Metadata

Windows.winmd

 

 

Show:
© 2014 Microsoft