Version

Clipboard Support (xamSyntaxEditor)

Topic Overview

Purpose

This topic explains the supported clipboard operations provided by the xamSyntaxEditor™ control.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

In this topic, you will find information to help you better understand the xamSyntaxEditor’s functions.

This topic covers the text editing capabilities of the xamSyntaxEditor control from both the developer and user’s perspective.

Introduction to the xamSyntaxEditor ’s Clipboard Support

Introduction

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.

Note
Note

In limited trust XBAP and Silverlight applications, the control uses a private clipboard, which provides full clipboard capability for text within the control, but does not allow clipboard interaction with other elements in the application.

Control Configuration Summary

Control configuration summary chart

The following table lists the commands available for the clipboard support.

Operation Details Command to invoke

Perform a Cut operation

  • Cut

Perform a Copy operation

  • Copy

Perform a Paste operation

  • Paste

For a complete lists of all xamSyntaxEditor commands, please refer to the Events and Commands topic.

Clipboard Cut

Overview

The cut clipboard operation captures and removes selected text from a document, while adding the selection to the clipboard.

Command settings

In order to: Instantiate the following command source: And set the following properties:

Perform the Cut operation

Example

In XAML:

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

Clipboard Copy

Overview

The copy clipboard operation copies the selected text from the document and adds it to the clipboard.

Command settings

In order to: Instantiate the following command source: And set the following properties:

Perform the Copy operation

SyntaxEditorCommandSource

EventName

CommandType

Example

In XAML:

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

Clipboard Paste

Overview

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.

Command settings

In order to: Instantiate the following command source: And set the following properties:

Perform the Paste operation

SyntaxEditorCommandSource

EventName

CommandType

Example

In XAML:

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

Events Summary

Events summary chart

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.

Event Details Event Properties

This event fires immediately before executing a clipboard operation prior to changing the TextDocument.

  • Clipboard operation

  • Clipboard content

  • Event can be canceled

This event fires immediately following executing a clipboard operation after changing the TextDocument.

  • Clipboard operation

  • Clipboard content

ClipboardOperationExecuting Event

Description

This event fires immediately preceding the execution of a clipboard operation prior to its making changes to the TextDocument.

Code

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

ClipboardOperationExecuted Event

Description

This event fires immediately following the execution of a clipboard operation following making changes to the TextDocument.

Code

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

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic lists the events and supported commands available to you, while building your xamSyntaxEditor applications.

This topic provides extensible information as well as samples about the Infragistics Commanding framework.