Edit this page

Clipboard Support

RadRichTextBox takes advantage of the clipboard support in Silverlight. However, as Silverlight's clipboard supports only plain text, copied content will be stripped of all formatting. For the needs of the control, it has a built-in rich text clipboard that allows copy/paste of text along with its formatting in one rich text box or between rich text boxes in the same application.

Furthermore, the API is extensible, so that you can implement a custom external clipboard, provided that you have the ability to obtain rich text from the clipboard.

Methods and Commands

RadRichTextBox's API exposes a method and a command for each of the three actions that can be performed against the clipboard: Cut, Copy and Paste. They can be evoked as follows:

this.radRichTextBox.Copy();
this.radRichTextBox.Cut();
this.radRichTextBox.Paste();
Me.radRichTextBox.Copy()
Me.radRichTextBox.Cut()
Me.radRichTextBox.Paste()

When building UI for the RichTextBox, the respective commands can be used:

<telerik:RadToolBar DataContext="{Binding ElementName=editor, Path=Commands}">
  <telerik:RadRibbonButton telerik:ScreenTip.Title="Cut" telerik:ScreenTip.Description="Cut the selection and put it on the Clipboard." CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=CutCommand}" Size="Medium" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/cut.png" Text="Cut" />
  <telerik:RadRibbonButton telerik:ScreenTip.Title="Copy" telerik:ScreenTip.Description="Copy the selection and put it on the Clipboard." CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=CopyCommand}" Size="Medium" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/copy.png" Text="Copy" />
  <telerik:RadRibbonButton telerik:ScreenTip.Title="Paste" telerik:ScreenTip.Description="Paste the contents of the Clipboard." CollapseToSmall="WhenGroupIsMedium" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=PasteCommand}" Size="Medium" SmallImage="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/paste.png" Text="Paste" />
</telerik:RadToolBar>

Note that the attached telerik:RadRichTextBoxRibbonUI.RichTextCommand property works only with Ribbon buttons. With regular RadButtons and other buttons, you should use their Command property instead.

Settings

In order to work around the limitation of the plain text only clipboard in Silverlight, we have exposed API for setting and getting the clipboard content of RadRichTextBox.

In that regard, we have introduced an interface – IExternalClipboard, which contains the following members:

public interface IExternalClipboard
{
    bool ContainsFragment();
    DocumentFragment GetFragment();
    void SetFragment(DocumentFragment fragment);
}

Basically, you should implement the interface and set the static property of ClipboardEx named ExternalClipboard:

ClipboardEx.ExternalClipboard = new RichTextExternalClipboard();

This will ensure that your methods will be used when the following operations are invoked:

  • Cut and Copy – in these cases the SetFragment(DocumentFragment fragment) method will be called. The fragment parameter includes the fragment that is currently copied, so that you can set it to the clipboard.

  • Paste – here the methods used are ContainsDocument() and GetFragment(). Basically, when the content of the clipboard is being set externally, a DocumentFragment must be created out of it. When paste is initiated, this DocumentFragment will be requested using the GetFragment() method if the ContainsFragment() method returns true.

Key Bindings

In order to copy, paste or cut, the standard keyboard shortcuts can also be used - Ctrl + C, Ctrl + V, Ctrl + X.

To learn more about the default key-bindings of the editor and ways to override them, you can refer to this article: Keyboard Support.

See Also

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy