Version

Managing Clipboard (xamRichTextEditor)

Topic Overview

Purpose

This topic explains the xamRichTextEditor ™ control’s clipboard operations from a developer’s perspective.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the features supported by the xamRichTextEditor control.

This topic explains the document’s content logical structure you can use to edit the contents in the xamRichTextEditor programmatically.

This topic provides detailed instructions to help you get up and running as quickly as possible with the xamRichTextEditor .

Introduction to the xamRichTextEditor’s Clipboard Support

Introduction

The xamRichTextEditor control provides Cut, Copy, and Paste clipboard operations allowing the user to edit the rich content of the document by moving or copying parts of the content at different locations. It is also possible to paste rich text content to and from other applications.

There must be selected content within the xamRichTextEditor for the Cut and Copy operations to be available. The Paste operation may be executed with, or without content selection.

  • If the document does not contain any selected content the clipboard’s contents is inserted after the current caret position

  • If the document contains selected content the clipboard’s content replaces the current selection

Clipboard Cut

Overview

The cut clipboard operation moves the selected content from the document to the clipboard and removes it from the document.

Details

In order to: Do the following: Details:

Perform the Cut operation using command

Instantiate the RichTextEditorCommandSource class

Set the following properties:

Perform the Cut operation using method

Invoke the Cut method

Code example using command

In XAML:

<Button Content="Cut">
    <ig:Commanding.Command>
        <igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Cut" />
    </ig:Commanding.Command>
</Button>

Code example using method

In C#:

this.xamRichTextEditor1.ActiveDocumentView.Selection.Cut();

In Visual Basic:

Me.xamRichTextEditor1.ActiveDocumentView.Selection.Cut()

Clipboard Copy

Overview

The copy clipboard operation copies the selected content from the document to the clipboard.

Details

In order to: Do the following: Details:

Perform the Copy operation using command

Instantiate the RichTextEditorCommandSource class

Set the following properties:

EventName

CommandType

Perform the Copy operation using method

Invoke the Copy method

Code example using command

In XAML:

<Button Content="Copy">
    <ig:Commanding.Command>
        <igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Copy" />
    </ig:Commanding.Command>
</Button>

Code example using method

In C#:

this.xamRichTextEditor1.ActiveDocumentView.Selection.Copy();

In Visual Basic:

Me.xamRichTextEditor1.ActiveDocumentView.Selection.Copy()

Clipboard Paste

Overview

The paste clipboard operation places the clipboard content at the xamRichTextEditor control’s current caret position or replaces the selection in the document if applicable.

Details

In order to: Do the following: Details:

Perform the Paste operation using command

Instantiate the RichTextEditorCommandSource class

Set the following properties:

EventName

CommandType

Perform the Paste operation using method

Invoke the Paste method

Code example using command

In XAML:

<Button Content="Paste">
    <ig:Commanding.Command>
        <igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Paste" />
    </ig:Commanding.Command>
</Button>

Code example using method

In C#:

this.xamRichTextEditor1.ActiveDocumentView.Selection.Paste();

In Visual Basic:

Me.xamRichTextEditor1.ActiveDocumentView.Selection.Paste()

ClipboardOperationExecuting Event

Overview

This event fires before executing a clipboard operation. The event handler provides an argument of type RichTextClipboardOperationCancelEventArgs, which can be used for the following purposes:

Details

In order to: Do the following:

Obtain the clipboard operation

Obtain the value of the ClipboardOperation property

Obtain the data object on which the clipboard operation will be performed.

Obtain the value of the DataObject property

Cancel the clipboard operation which is about the be executed

Set the Cancel property to true

Code example

In C#:

void xamRichTextEditor1_ClipboardOperationExecuting(object sender, RichTextClipboardOperationCancelEventArgs e)
{
    // obtain clipboard operation
    ClipboardOperation operation = e.ClipboardOperation;
    // obtain clipboard content as text
    string s = e.DataObject.GetData("Text") as string;
    // cancel the clipboard operation if a condition occur
    e.Cancel = true;
}

In Visual Basic:

Private Sub xamRichTextEditor1_ClipboardOperationExecuting(sender As Object, e As RichTextClipboardOperationCancelEventArgs)
      ' obtain clipboard operation
      Dim operation As ClipboardOperation = e.ClipboardOperation
      ' obtain clipboard content as text
      Dim s As String = TryCast(e.DataObject.GetData("Text"), String)
      ' cancel the clipboard operation if a condition occur
      e.Cancel = True
End Sub

ClipboardOperationExecuted Event

Overview

This event fires after executing a clipboard operation. The event handler provides an argument of type RichTextClipboardOperationEventArgs, which can be used for the following purposes:

Details

In order to: Do the following:

Obtain the clipboard operation

Obtain the value of the ClipboardOperation property

Obtain the data object on which the clipboard operation was performed.

Obtain the value of the DataObject property

Code example

In C#:

void xamRichTextEditor1_ClipboardOperationExecuted(object sender, ClipboardOperationEventArgs e)
{
    // obtain clipboard operation
    ClipboardOperation operation = e.ClipboardOperation;
    // obtain clipboard content as text
    string s = e.DataObject.GetData("Text") as string;
}

In Visual Basic:

Private Sub xamRichTextEditor1_ClipboardOperationExecuted(sender As Object, e As ClipboardOperationEventArgs)
      ' obtain clipboard operation
      Dim operation As ClipboardOperation = e.ClipboardOperation
      ' obtain clipboard content as text
      Dim s As String = TryCast(e.DataObject.GetData("Text"), String)
End Sub

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to turn on the xamRichTextEditor control’s multiple selection functionality.

This topic covers the xamRichTextEditor control’s selection feature from the developer’s perspective.