Version

Custom Margins (xamSyntaxEditor)

Topic Overview

Purpose

This topic explains how to create your own margins.

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.

In this topic

This topic contains the following sections:

Create a Custom Margin

Introduction

The xamSyntaxEditor ™ supports placing margins in any of the four locations along the edges of the text editing area. To be able to position a margin in any of the four locations (top, bottom, left or right) the MarginBase class implements the ISupportPositioning interface. You will most likely use left and right positioned margins to display information related to the text rows and top or bottom positioned margins to display information related to the text columns.

The xamSyntaxEditor is responsible for arranging all margins at the appropriate locations. The xamSyntaxEditor also ensures that all margins have presenters by invoking the CreatePresenter method and passing the associated DocumentViewBase as an argument. The DocumentViewBase provides the presenter with the needed context to access the view and the control information (for example, access to visible lines, events for different user interactions, etc…).

Steps

The following steps demonstrate how to create a custom margin.

1. Create a Margin class

Create your custom margin class by extending from the MarginBase class.

2. Set Margin Location

Override the Location property of MarginBase to position your margin at the desired location.

3. Set Margin Arrangement

Override the After and Before members of the ISupportPositioning interface to position your margin along the other margins at this location.

4. Provide a Unique Margin Key

Override the Key property of MarginBase to give your margin a unique key so that other margins can position themselves relative to your margin.

5. Provide a Presenter for your Margin

Override the CreatePresenter method of MarginBase to provide the presenter for your margin. The presenter can be any class extending from FrameworkElement.

6. Add logic to your Presenter to render your margin’s content

Custom margin presenters typically override the DocumentViewBase.LayoutChanged event to trigger the rendering of the custom margin’s content.

7. Add the Margin in the xamSyntaxEditor

Add your margin in the CustomMargins collection of the xamSyntaxEditor .

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes the use and configuration of the xamSyntaxEditor control’s built-in Line Number Margin.

This topic explains how to configure the ruler margin feature.