New to Telerik UI for WPF? Start a free 30-day trial

A class providing additional methods for working with the clipboard.

Definition

Namespace:Telerik.Windows.Documents.Base

Assembly:Telerik.Windows.Controls.RichTextBox.dll

Syntax:

C#
public static class ClipboardEx

Inheritance: objectClipboardEx

Properties

Collection of ClipboardHandlers that will be used when getting rich-text content from the clipboard.

C#
public static List<ClipboardHandler> ClipboardHandlers { get; }
Property Value:

The clipboard handlers.

Methods

Determines whether the clipboard contains supported rich-text data.

C#
public static bool ContainsDocument()
Returns:

bool

true if the clipboard contains document; otherwise, false.

Determines whether the clipboard contains plain text.

C#
public static bool ContainsText(KeyEventArgs pasteKeyEventArgs)
Parameters:pasteKeyEventArgsKeyEventArgs

The KeyEventArgs instance containing the event data. Use null if such is not present./>

Returns:

bool

true if the clipboard contains text; otherwise, false.

Obtains a DocumentFragment from the clipboard using the registered ClipboardHandlers.

C#
public static DocumentFragment GetDocument()
Returns:

DocumentFragment

a DocumentFragment instance representing the document created from the content inside the clipboard. If the operation is not successful, the method returns null.

Obtains a DocumentFragment from the clipboard using the registered ClipboardHandlers.

C#
public static DocumentFragment GetDocument(out PasteSource? pasteSource)
Parameters:pasteSourcePasteSource?

The PasteSource that is resolved during clipboard processing.

Returns:

DocumentFragment

a DocumentFragment instance representing the document created from the content inside the clipboard. If the operation is not successful, the method returns null.

Gets a DocumentFragment from clipboard using the specified data format.

C#
public static DocumentFragment GetDocumentFromClipboard(string dataFormat, Func<string, string> clipboardStringFilter = null)

dataFormat

string

The data format. You can use the set of formats provided in the class.

clipboardStringFilter

Func<string, string>

A function to filter the string inside the clipboard. This function is used when the content needs to be formatted additionally before creating a document from it.

        <p>HTML content inserted by MS Word can be stripped using <xref href="Telerik.Windows.Documents.Base.ClipboardEx.StripHtmlClipboardFormatHeaders(System.String)" data-throw-if-not-resolved="false"></xref>.</p>
Returns:

DocumentFragment

A DocumentFragment instance representing the content. If the operation did not succeed, the method return null.

Only the text, Unicode text, OEM text, RTF, HTML and XAML formats are read. For any other format the method returns null; data stored in custom clipboard formats is never deserialized.

Gets a DocumentFragment from clipboard using the specified data format.

C#
public static DocumentFragment GetDocumentFromClipboard(string dataFormat, out PasteSource? pasteSource, Func<string, string> clipboardStringFilter = null)

dataFormat

string

The data format. You can use the set of formats provided in the class.

pasteSource

PasteSource?

The PasteSource that is resolved during clipboard processing.

clipboardStringFilter

Func<string, string>

A function to filter the string inside the clipboard. This function is used when the content needs to be formatted additionally before creating a document from it.

        <p>HTML content inserted by MS Word can be stripped using <xref href="Telerik.Windows.Documents.Base.ClipboardEx.StripHtmlClipboardFormatHeaders(System.String)" data-throw-if-not-resolved="false"></xref>.</p>
Returns:

DocumentFragment

A DocumentFragment instance representing the content. If the operation did not succeed, the method return null.

Only the text, Unicode text, OEM text, RTF, HTML and XAML formats are read. For any other format the method returns null; data stored in custom clipboard formats is never deserialized.

Gets the clipboard data of type .

C#
public static string GetText()
Returns:

string

The string representing the content or Empty if there is no text in the clipboard.

Places a specified data object in the system Clipboard.

C#
public static void SetDataObject(IDataObject dataObject)
Parameters:dataObjectIDataObject

A data object (an object that implements IDataObject) to place on the system Clipboard.

Sets a document represented by a DocumentFragment instance to the specified data object.

C#
public static void SetDocument(DocumentFragment documentFragment, IDataObject dataObject)
Parameters:documentFragmentDocumentFragment

The document fragment.

dataObjectIDataObject

The object the document fragment should be inserted into.

Sets a document represented by a DocumentFragment instance to the system clipboard.

C#
public static void SetDocument(DocumentFragment documentFragment)
Parameters:documentFragmentDocumentFragment

The document fragment.

Stores data, specified as a string, in the specified data object.

C#
public static void SetText(string textData, DataObject dataObject)
Parameters:textDatastring

The string representing the text data.

dataObjectDataObject

The data object.

Stores data, specified as a string, in the system clipboard.

C#
public static void SetText(string textData)
Parameters:textDatastring

The text data.

Strips the clipboard format headers from the HTML content inserted in the clipboard by MS Word. Skips all lines in the beginning containing ':'.

C#
public static string StripHtmlClipboardFormatHeaders(string clipboardText)
Parameters:clipboardTextstring

The clipboard text.

Returns:

string

The stripped HTML string.