<Button Content="Cut">
<ig:Commanding.Command>
<igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Cut" />
</ig:Commanding.Command>
</Button>
This topic explains the xamRichTextEditor ™ control’s clipboard operations from a developer’s perspective.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
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
The cut clipboard operation moves the selected content from the document to the clipboard and removes it from the document.
In XAML:
<Button Content="Cut">
<ig:Commanding.Command>
<igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Cut" />
</ig:Commanding.Command>
</Button>
In C#:
this.xamRichTextEditor1.ActiveDocumentView.Selection.Cut();
In Visual Basic:
Me.xamRichTextEditor1.ActiveDocumentView.Selection.Cut()
The copy clipboard operation copies the selected content from the document to the clipboard.
In XAML:
<Button Content="Copy">
<ig:Commanding.Command>
<igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Copy" />
</ig:Commanding.Command>
</Button>
In C#:
this.xamRichTextEditor1.ActiveDocumentView.Selection.Copy();
In Visual Basic:
Me.xamRichTextEditor1.ActiveDocumentView.Selection.Copy()
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.
In XAML:
<Button Content="Paste">
<ig:Commanding.Command>
<igPrim:RichTextEditorCommandSource EventName="Click" CommandType="Paste" />
</ig:Commanding.Command>
</Button>
In C#:
this.xamRichTextEditor1.ActiveDocumentView.Selection.Paste();
In Visual Basic:
Me.xamRichTextEditor1.ActiveDocumentView.Selection.Paste()
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:
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
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:
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
The following topics provide additional information related to this topic.