Clipboard Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets and sets information from the clipboard object.
public ref class Clipboard abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class Clipboard final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Clipboard final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public static class Clipboard
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class Clipboard
Public Class Clipboard
- Inheritance
- Attributes
Windows requirements
Device family |
Windows 10 (introduced in 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced in v1.0)
|
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.
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;
}
}
Tip
For more info, design guidance, and code examples, see Copy and paste.
The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub
Remarks
Because the Clipboard class is a static class, you don't need to create an instance of it to access its methods.
You can only access the clipboard when the calling application is in focus on the UI thread (for example, when its 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() |
Removes all data from the Clipboard. |
ClearHistory() |
Clears the clipboard history. |
DeleteItemFromHistory(ClipboardHistoryItem) |
Deletes the specified item from the clipboard history. |
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. |
GetHistoryItemsAsync() |
Gets the list of items currently in the clipboard history. |
IsHistoryEnabled() |
Indicates whether clipboard history (that is, the ability to save multiple items to the clipboard) is enabled for the current user. |
IsRoamingEnabled() |
Indicates whether clipboard data is set to sync across devices for the current user. |
SetContent(DataPackage) |
Sets the current content that is stored in the clipboard object. |
SetContentWithOptions(DataPackage, ClipboardContentOptions) |
Sets the content that is stored in the clipboard object with options for the content. |
SetHistoryItemAsContent(ClipboardHistoryItem) |
Sets an item in the clipboard history as the current content for the clipboard. |
Events
ContentChanged |
Occurs when the data stored in the Clipboard changes. |
HistoryChanged |
Occurs when a new item is added to the clipboard history. |
HistoryEnabledChanged |
Occurs when the OS setting that controls whether clipboard history is enabled for the current user is changed. |
RoamingEnabledChanged |
Occurs when the OS setting that controls whether clipboard data is set to sync across devices for the current user is changed. |