<Button Content="Cut">
<ig:Commanding.Command>
<igPrim:SyntaxEditorCommandSource EventName="Click" CommandType="Cut" />
</ig:Commanding.Command>
</Button>
This topic explains the supported clipboard operations provided by the xamSyntaxEditor™ control.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
The xamSyntaxEditor control provides Cut, Copy and Paste to clipboard operation to facilitate users editing of document. These operations are available using the Infragistics Commanding framework.
The following table lists the commands available for the clipboard support.
For a complete lists of all xamSyntaxEditor commands, please refer to the Events and Commands topic.
The cut clipboard operation captures and removes selected text from a document, while adding the selection to the clipboard.
In XAML:
<Button Content="Cut">
<ig:Commanding.Command>
<igPrim:SyntaxEditorCommandSource EventName="Click" CommandType="Cut" />
</ig:Commanding.Command>
</Button>
The copy clipboard operation copies the selected text from the document and adds it to the clipboard.
In XAML:
<Button Content="Copy">
<ig:Commanding.Command>
<igPrim:SyntaxEditorCommandSource EventName="Click" CommandType="Copy" />
</ig:Commanding.Command>
</Button>
The paste clipboard operation either inserts the clipboard’s textual content at the xamSyntaxEditor’s current caret position or inserts and replaces selected text in the document, if applicable.
In XAML:
<Button Content="Paste">
<ig:Commanding.Command>
<igPrim:SyntaxEditorCommandSource EventName="Click" CommandType="Paste" />
</ig:Commanding.Command>
</Button>
The execution of clipboard operations fires the xamSyntaxEditor control’s ClipboardOperationExecuting event before making changes to the TextDocument,
and later fires the ClipboardOperationExecuted following a clipboard operation committing changes to the TextDocument
. Cancelling the ClipboardOperationExecuting
event prevents the ClipboardOperationExecuted
event from firing and aborts the current clipboard operation. Regardless of whether triggered by the executing or executed event you can retrieve the requested clipboard operation (Cut, Copy or Paste) along with its contents.
The following table lists the clipboard events, fired by the xamSyntaxEditor control.
This event fires immediately preceding the execution of a clipboard operation prior to its making changes to the TextDocument
.
The following code snippet shows how to handle a ClipboardOperationExecuting
event:
In C#:
public void editor_COExecuting(object s, ClipboardOperationExecutingEventArgs e)
{
// obtain clipboard operation (Cut, Copy, Paste)
ClipboardOperation operation = e.ClipboardOperation;
// get the data object in order to operate with the clipboard data
SyntaxEditorDataObject dataObject = e.DataObject;
string dataAsString =
dataObject.GetData(SyntaxEditorDataFormats.Text) as string;
// you can change the clipboard data
dataObject.SetData(SyntaxEditorDataFormats.Text, "new string");
// or cancel the event and the entire clipboard operation
e.Cancel = true;
}
In Visual Basic:
Public Sub editor_COExecuting(s As Object, e As ClipboardOperationExecutingEventArgs)
' obtain clipboard operation (Cut, Copy, Paste)
Dim operation As ClipboardOperation = e.ClipboardOperation
' get the data object in order to operate with the clipboard data
Dim dataObject As SyntaxEditorDataObject = e.DataObject
Dim dataAsString As String = _
TryCast(dataObject.GetData(SyntaxEditorDataFormats.Text), String)
' you can change the clipboard data
dataObject.SetData(SyntaxEditorDataFormats.Text, "new string")
' or cancel the event and the entire clipboard operation
e.Cancel = True
End Sub
This event fires immediately following the execution of a clipboard operation following making changes to the TextDocument
.
The following code snippet shows how to handle a ClipboardOperationExecuted
event:
In C#:
public void editor_COExecuted(object s, ClipboardOperationExecutingEventArgs e)
{
// obtain clipboard operation (Cut, Copy, Paste)
ClipboardOperation operation = e.ClipboardOperation;
// get the data object in order to operate with the clipboard data
SyntaxEditorDataObject dataObject = e.DataObject;
string dataAsString =
dataObject.GetData(SyntaxEditorDataFormats.Text) as string;
}
In Visual Basic:
Public Sub editor_COExecuted(s As Object, e As ClipboardOperationExecutingEventArgs)
' obtain clipboard operation (Cut, Copy, Paste)
Dim operation As ClipboardOperation = e.ClipboardOperation
' get the data object in order to operate with the clipboard data
Dim dataObject As SyntaxEditorDataObject = e.DataObject
Dim dataAsString As String = _
TryCast(dataObject.GetData(SyntaxEditorDataFormats.Text), String)
End Sub
The following topics provide additional information related to this topic.