# Footnotes

> Add footnotes to documents in a WPF TextControl: connect the RibbonReferencesTab in XAML, insert and number footnotes in C#, navigate, remove and handle events.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Editor > Footnotes
- **4916 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/footnotes/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/footnotes/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/footnotes/llms-full.txt

---

A footnote places a comment or a source at the bottom of the page without breaking the flow of the text. The WPF `TextControl` supports footnotes in the user interface, through the **References** tab of the ribbon, and in code, through its `Footnotes` collection: insert them, number them, go from one to the next and react when the user works with them.

The examples use a window with a `TextControl` named `textControl1`, as in [Create Your First WPF Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/llms-full.txt). Footnotes were introduced in version 32.0 and are part of the Enterprise edition; see [Editions and Feature Availability](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/editions/llms-full.txt).

### Reference Marks and Footnotes

Every footnote consists of two parts:

- **The reference mark**, a number at the position in the text that the footnote refers to.
- **The footnote** at the bottom of the page. It begins with a footnote mark, which repeats the number, followed by the footnote text.

All footnotes of a document share one number format and one start number, and they are numbered from the beginning to the end of the document. A footnote inserted in front of others gets the lower number, and the following footnotes are renumbered. The footnote text can be formatted like any other text and can contain tables and images.

Only the main text can hold footnotes; headers, footers and text frames can't. Footnotes are saved in the TX Text Control format (*.tx*), in RTF and in the Word formats DOC and DOCX.

[WPF.TextControl.Footnotes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotes-property/llms-full.txt) returns a [FootnoteCollection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/llms-full.txt) with one [Footnote](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/llms-full.txt) object per footnote. These classes are the same in the Windows Forms and WPF products; the footnote events are members of the WPF `TextControl`:

![Class diagram of the footnote API: the Footnotes property and footnote events of TextControl and WPF.TextControl, FootnoteCollection, Footnote, FootnoteEventArgs, FootnoteSection and FootnoteText.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/footnotes-class-diagram.37521bf5.webp)

### Connect the References Tab

[WPF.RibbonReferencesTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreferencestab/llms-full.txt) is a ribbon tab with a **Footnotes** group. Its buttons insert a footnote, delete and edit the current one, go to the previous or next footnote and highlight the marks, and two more items set the start number and the number format.

The tab goes into a `Ribbon` in *MainWindow.xaml*. The `TextControl` finds it through its name, which you assign to the [RibbonReferencesTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonreferencestab-property/llms-full.txt) property. The following window also has a row of buttons for the code in the next sections:

```xml
<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        Title="MainWindow" Height="600" Width="900">
    <DockPanel>
        <Ribbon DockPanel.Dock="Top">
            <WPF:RibbonReferencesTab x:Name="ribbonReferencesTab" />
        </Ribbon>
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
            <Button Content="Insert Footnote" Click="InsertFootnote_Click" />
            <Button Content="List Footnotes" Click="ListFootnotes_Click" />
            <Button Content="Next Footnote" Click="NextFootnote_Click" />
            <Button Content="Remove Footnote" Click="RemoveFootnote_Click" />
        </StackPanel>
        <WPF:TextControl x:Name="textControl1"
                        RibbonReferencesTab="ribbonReferencesTab"
                        Loaded="textControl1_Loaded"
                        FootnoteReferenceMarkEntered="textControl1_FootnoteReferenceMarkEntered" />
    </DockPanel>
</Window>
```

Replace `SampleApp` with the namespace of your project. [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon/llms-full.txt) and [Connecting Ribbon Tabs in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon-xaml/llms-full.txt) describe the ribbon tabs and how they are connected.

### Set the Number Format When the Control Is Loaded

The numbering belongs to the collection. Set it in *MainWindow.xaml.cs*, in the handler of the `Loaded` event of the `TextControl` that the XAML above connects:

```csharp
using System.Text;
using System.Windows;
using TXTextControl;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void textControl1_Loaded(object sender, RoutedEventArgs e)
    {
        // Number all footnotes i, ii, iii and highlight their marks
        textControl1.Footnotes.NumberFormat = NumberFormat.SmallRomanNumbers;
        textControl1.Footnotes.StartNumber = 1;
        textControl1.Footnotes.HighlightMode = HighlightMode.Always;
        textControl1.Focus();
    }
}
```

Keep the `namespace` that Visual Studio created around the class. Add the handlers of the following sections to the same class.

- [NumberFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/numberformat-property/llms-full.txt) is a value of [NumberFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/numberformat/enumeration/llms-full.txt): `ArabicNumbers`, `Letters`, `CapitalLetters`, `RomanNumbers` or `SmallRomanNumbers`.
- [StartNumber](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/startnumber-property/llms-full.txt) is the number of the first footnote.
- [HighlightMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/highlightmode-property/llms-full.txt) highlights the reference and footnote marks of all footnotes: `Always`, `Never` (the default) or `Activated`, which highlights the marks that contain the input position. [Footnote.HighlightMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/highlightmode-property/llms-full.txt) and [Footnote.HighlightColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/highlightcolor-property/llms-full.txt) change it for a single footnote. `HighlightColor` is a `System.Drawing.Color`, not a WPF color.

### Insert a Footnote

The **Insert Footnote** button inserts a footnote at the input position:

```csharp
private void InsertFootnote_Click(object sender, RoutedEventArgs e)
{
    // The footnote text, a name and an ID; 0 means no ID
    Footnote footnote = new Footnote("Source: annual report 2025, page 12.", "source", 0);

    // true: move the input position into the footnote text
    if (!textControl1.Footnotes.Add(footnote, true))
    {
        MessageBox.Show(this, "A footnote can't be inserted at this position.");
    }

    // Give the keyboard focus back to the editor
    textControl1.Focus();
}
```

- The [Footnote constructor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/constructor/llms-full.txt) takes the footnote text and, optionally, a name and an ID that identify the footnote in your code. An empty name and an ID of 0 mean none.
- [FootnoteCollection.Add](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/add-method/llms-full.txt) inserts the reference mark and the footnote. With `true`, the input position moves into the footnote text so that the user can continue typing there. It returns `false` where no footnote can be inserted.
- `Focus` gives the keyboard focus back to the `TextControl` after the click on the button, so that the user can type the footnote text.

To edit the text of an existing footnote, call [Footnote.Edit](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/edit-method/llms-full.txt): it sets the input position at the end of the footnote text, where it can be changed and formatted like other text.

### List, Find and Remove Footnotes

```csharp
private void ListFootnotes_Click(object sender, RoutedEventArgs e)
{
    StringBuilder list = new StringBuilder();

    foreach (Footnote footnote in textControl1.Footnotes)
    {
        // Text begins with the footnote mark
        list.AppendLine(footnote.Number + " (" + footnote.Name + "): " + footnote.Text);
    }

    MessageBox.Show(this, list.ToString(), textControl1.Footnotes.Count + " footnotes");
}

private void NextFootnote_Click(object sender, RoutedEventArgs e)
{
    // true: the next footnote after the input position, false: the previous one
    Footnote footnote = textControl1.Footnotes.GetItem(true);
    footnote?.ScrollTo();
}

private void RemoveFootnote_Click(object sender, RoutedEventArgs e)
{
    Footnote footnote = textControl1.Footnotes.GetItem("source");

    if (footnote != null)
    {
        textControl1.Footnotes.Remove(footnote);
    }
}
```

The code works as follows:

- [Number](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/number-property/llms-full.txt) is the number of the footnote in the text flow, starting with 1; the indexer `textControl1.Footnotes[1]` returns a footnote by this number. [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/text-property/llms-full.txt) is the plain footnote text with the footnote mark in front of it. [Footnote.Save](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/save-method/llms-full.txt) returns it in a format such as RTF or HTML.
- [GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/getitem-method/llms-full.txt) returns the footnote at the input position, the next (`true`) or previous (`false`) one, or the one with an ID or a name, and `null` when there is none.
- [ScrollTo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/scrollto-method/llms-full.txt) sets the input position at the footnote mark and scrolls it into view.
- [Remove](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnotecollection/remove-method/llms-full.txt) deletes the footnote with its reference mark and renumbers the following ones.

#### Name, ID and Reference Mark of a Footnote

The name and the ID given to the constructor stay available as properties of the footnote, which your code can read and change later. [Name](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/name-property/llms-full.txt) is a string, empty for a footnote without a name, and [ID](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/id-property/llms-full.txt) a number of your choice starting at 1, where 0 means none. Two read-only properties locate the reference mark in the text: [ReferenceMarkStart](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/referencemarkstart-property/llms-full.txt) is the one-based index of its first character and [ReferenceMarkLength](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/referencemarklength-property/llms-full.txt) the number of its characters.

The following handlers select the reference mark of the footnote named "source", and move to the footnote at the input position with its footnote mark at the top of the visible part:

```csharp
private void SelectReferenceMark_Click(object sender, RoutedEventArgs e)
{
    Footnote footnote = textControl1.Footnotes.GetItem("source");

    if (footnote != null)
    {
        // ReferenceMarkStart is one-based, Select expects a zero-based position
        textControl1.Select(footnote.ReferenceMarkStart - 1, footnote.ReferenceMarkLength);
    }
}

private void ShowFootnote_Click(object sender, RoutedEventArgs e)
{
    // The footnote at the input position, or null
    Footnote footnote = textControl1.Footnotes.GetItem();

    // Move to the footnote mark and scroll it to the top
    footnote?.ScrollTo(InputPosition.ScrollPosition.Top);
}
```

[WPF.TextControl.Select](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/select-method/llms-full.txt) sets the start and length of the selection. `ScrollTo()` without a parameter chooses the scroll position itself and returns `true` if the document was scrolled; the overload with an [InputPosition.ScrollPosition](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputposition/scrollposition-enumeration/llms-full.txt) value (`Left`, `Top`, `Right` or `Bottom`) places the footnote mark at that side of the visible part. Both overloads move the input position to the footnote mark.

The static [Footnote.DefaultHighlightColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/defaulthighlightcolor-property/llms-full.txt) returns the default highlight color of the reference and footnote marks, a `System.Drawing.Color` like [HighlightColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnote/highlightcolor-property/llms-full.txt). To reset the color of one footnote, write `footnote.HighlightColor = Footnote.DefaultHighlightColor;`.

### Handle Footnote Events

The events are declared on the WPF `TextControl`, and you connect them in XAML like the `FootnoteReferenceMarkEntered` attribute in the window above. Each handler receives a [FootnoteEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnoteeventargs/llms-full.txt) whose [Footnote](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/footnoteeventargs/footnote-property/llms-full.txt) property is the footnote concerned:

| Event | Occurs when |
|---|---|
| [FootnoteCreated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotecreated-event/llms-full.txt) | A footnote has been inserted |
| [FootnoteDeleted](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotedeleted-event/llms-full.txt) | A footnote has been deleted |
| [FootnoteReferenceMarkEntered](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotereferencemarkentered-event/llms-full.txt) | The input position moves onto a reference mark |
| [FootnoteReferenceMarkLeft](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotereferencemarkleft-event/llms-full.txt) | The input position leaves a reference mark |
| [FootnoteSectionActivated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotesectionactivated-event/llms-full.txt) | The footnote text at the bottom of a page gets the input position |
| [FootnoteSectionDeactivated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/footnotesectiondeactivated-event/llms-full.txt) | The footnote text loses the input position |

The handler below shows the footnote text in the title bar of the window while the cursor is on a reference mark:

```csharp
private void textControl1_FootnoteReferenceMarkEntered(object sender, FootnoteEventArgs e)
{
    Title = "Footnote " + e.Footnote.Number + ": " + e.Footnote.Text;
}
```

A [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt), which processes documents without a user interface, has a [Footnotes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/footnotes-property/llms-full.txt) collection as well and raises [FootnoteCreated](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/footnotecreated-event/llms-full.txt) and [FootnoteDeleted](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/footnotedeleted-event/llms-full.txt) with the same `FootnoteEventArgs`. The other four events concern the input position and exist only in the editor controls, such as the WPF `TextControl`.

[Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/llms-full.txt) lists all events of the WPF `TextControl`.

### Next Steps

- [Tables of Contents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/tables-of-contents/llms-full.txt): list the headings of a document with page numbers.
- [Headers and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/headers-footers/llms-full.txt): text that repeats at the top and bottom of every page.
- [Text and Paragraph Formatting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/formatting/llms-full.txt): format the footnote text.
- The blog article [Sneak Peek 32.0: Introducing Footnotes](https://www.textcontrol.com/blog/2023/06/23/sneak-peek-320-introducing-footnotes/): the footnote feature with formatted text and tables.

---

## Nearby

- **Previous:** [Sections and Page Layout](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/sections/llms-full.txt)
- **Next:** [Tables of Contents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/tables-of-contents/llms-full.txt)
