Export (0) Print
Expand All

Clipboard Class

Provides static methods that facilitate transferring data to and from the system clipboard. In Silverlight 5, this access is limited to Unicode text strings.

System.Object
  System.Windows.Clipboard

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public static class Clipboard

The Clipboard type exposes the following members.

  NameDescription
Public methodStatic memberSupported by Silverlight for Windows PhoneContainsTextQueries the clipboard for the presence of data in the UnicodeText format.
Public methodStatic memberSupported by Silverlight for Windows PhoneGetTextRetrieves Unicode text data from the system clipboard, if Unicode text data exists.
Public methodStatic memberSupported by Silverlight for Windows PhoneSetTextSets Unicode text data to store on the clipboard, for later access with GetText.
Top

In Silverlight 5, access to clipboard information is limited to Unicode text access. This differs from the WPF implementation of Clipboard, which enables access to other specific types (for example, streams or images) or to data objects.

In partial trust (the default mode for browser-hosted Silverlight-based applications), Silverlight also restricts clipboard access to its two key APIs GetText and SetText. These APIs can only be invoked from within a context that is determined by the Silverlight runtime to be in response to a user-initiated action. For example, clipboard access is valid from within a handler for a Click or KeyDown event. In contrast, clipboard access is not valid from a handler for Loaded or from a constructor, and access attempts throw exceptions.

In addition, Silverlight prompts the user for confirmation if the clipboard is accessed under partial trust. This Silverlight access-confirmation dialog box is displayed one time per session. If you specifically produce an out-of-browser application and request elevated trust, this security restriction on the API and its dialog box are not used. For more information, see Trusted Applications.

Certain controls (for example, TextBox and RichTextBox) also support a form of clipboard access. In these cases, the control provides class-based event handling for certain input events (for example, KeyDown). The control provides the infrastructure for integrating with the system clipboard without requiring a control's consumer to specifically handle input events or call Clipboard API. For example, the key handling of Ctrl+C might copy any selected plaintext from the control to the system clipboard, and Ctrl+V might paste plaintext to a focused region of a control that can present text content. These controls both populate and use the clipboard. This type of behavior is specific to each control, and you should read the class documentation topics for these controls to obtain more information.

In order to be useful for a clipboard Cut or Copy scenario, a Silverlight UI element must support a concept of selection of regions that might contain text. In order to be useful for a clipboard Paste scenario, a Silverlight UI element must be able to present text. Typically, such a UI element should support a text insertion point.

Silverlight 5 supports a related drag-and-drop scenario in which a UIElement can be a drop target for a data payload that communicates a file list. However, this scenario does not directly involve the Clipboard class, and uses specific event data and the DataObject class. For more information, see AllowDrop.

Version Notes

Silverlight for Windows Phone Silverlight for Windows Phone

You cannot get clipboard text from a Windows Phone application, only set it. Calling the GetText method in a Windows Phone application will always cause a SecurityException to occur.

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft