# Bullets and Numbered Lists

> Build bulleted, numbered and multilevel lists in a WPF editor with ListFormat, restart numbering with list styles and read list numbers of paragraphs in code.

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

---

Agendas, instructions, contract clauses and outlines need bullets or numbers that renumber themselves when an item is added. In the WPF `TextControl`, bulleted, numbered and multilevel lists are attributes of paragraphs, described by a `ListFormat` object. Users set them with the ribbon and the **Bullets and Numbering** dialog box. The examples below create each kind of list in code, restart the numbering, define list styles and read the numbers the editor displays.

The other attributes of paragraphs are in [Text and Paragraph Formatting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/formatting/llms-full.txt). The code goes into *MainWindow.xaml.cs* with `using TXTextControl;`.

### How Lists Work

Each paragraph of a list has a [ListFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/llms-full.txt). Its [Type](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/type-property/llms-full.txt), a [ListType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listtype/enumeration/llms-full.txt) value, decides what kind of list the paragraph belongs to:

| Value | Meaning |
|---|---|
| `None` | No list |
| `Bulleted` | A bulleted list |
| `Numbered` | A numbered list |
| `Structured` | A structured list, in which each number is preceded by the numbers of all higher levels, such as 2.1.3. |

- **Levels** go from 1 to 10, the value of [MaxLevel](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/maxlevel-field/llms-full.txt), and [Level](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/level-property/llms-full.txt) is 1 by default.
- **Numbering** continues across lists until [RestartNumbering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/restartnumbering-property/llms-full.txt) starts a new list at [FirstNumber](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/firstnumber-property/llms-full.txt), which is 1 by default.
- **Position.** [HangingIndent](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/hangingindent-property/llms-full.txt), 360 twips by default, and [LeftIndent](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/leftindent-property/llms-full.txt) place the bullet or number and the text. [FormatCharacter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/formatcharacter-property/llms-full.txt) separates them with a `Tab` (the default), a `Space` or `None`.
- **Mixed selections.** For a selection whose paragraphs have different settings, the `ListFormat` properties return their defaults; [IsCommonValueSelected](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/iscommonvalueselected-method/llms-full.txt) tells whether a value is common to all of them.

### Open the Bullets and Numbering Dialog Box

The text mini toolbar and the formatting tab of the WPF ribbon have list buttons. From your own menu, [ListFormatDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/listformatdialog-method/llms-full.txt) opens the **Bullets and Numbering** dialog box for the selected paragraphs. With `<MenuItem Header="Bullets and Numbering..." Click="MenuItemBullets_Click" />` in the XAML:

```csharp
private void MenuItemBullets_Click(object sender, RoutedEventArgs e)
{
    TXTextControl.WPF.DialogResult result = textControl1.ListFormatDialog();
}
```

The dialog box sets the formatting attributes of bulleted and numbered lists, including any Unicode character from any font as the bullet. The method returns `Cancel` when the user canceled the dialog box or changed nothing.

The dialog box offers the list types, the positions of the bullet or number and of the text, the separating character, the level, the bullet character and its size, and for numbered lists the number style, the start number, the text in front of and after the number, and whether to restart the numbering or continue the list:

![The Bullets and Numbering dialog box with the numbered list type selected, the formatting options, the bullet characters, the number format settings and the Restart numbering option marked.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/bullets-numbering-dialog.f8649bcb.webp)

### Create a Bulleted List

Create a `ListFormat`, set its attributes and assign it to [Selection.ListFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/listformat-property/llms-full.txt). This handler makes the selected paragraphs a bulleted list with a round bullet from Arial:

```csharp
private void bulletsButton_Click(object sender, RoutedEventArgs e)
{
    ListFormat bullets = new ListFormat(ListType.Bulleted);
    bullets.BulletCharacter = '•';
    bullets.FontName = "Arial";

    textControl1.Selection.ListFormat = bullets;
}
```

[BulletCharacter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/bulletcharacter-property/llms-full.txt) is by default the character B7 (hexadecimal) of the Windows Symbol font. Since version 23.0, any Unicode character works, taken from the font that [FontName](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/fontname-property/llms-full.txt) names; without a font name, the Symbol font is assumed. [BulletSize](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/bulletsize-property/llms-full.txt) 0, the default, sizes the bullet like the list text.

### Create a Numbered List

```csharp
private void numbersButton_Click(object sender, RoutedEventArgs e)
{
    ListFormat numbers = new ListFormat(ListType.Numbered);
    numbers.NumberFormat = NumberFormat.ArabicNumbers;
    numbers.TextAfterNumber = ".";
    numbers.FormatCharacter = ListFormatCharacter.Tab;

    textControl1.Selection.ListFormat = numbers;
}
```

- [NumberFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/numberformat-property/llms-full.txt) takes a [NumberFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/numberformat/enumeration/llms-full.txt) value: `ArabicNumbers` (1, 2, 3), `Letters` (a, b, c), `CapitalLetters` (A, B, C), `RomanNumbers` (I, II, III) or `SmallRomanNumbers` (i, ii, iii).
- [TextBeforeNumber](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/textbeforenumber-property/llms-full.txt) and [TextAfterNumber](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/textafternumber-property/llms-full.txt) put up to 20 characters ([MaxText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/listformat/maxtext-field/llms-full.txt)) around the number, for example "Step " before and ":" after it. The older `CharBeforeNumber` and `CharAfterNumber` are obsolete.

### Create a Multilevel List

In a structured list, a paragraph at level 2 shows the number of the level 1 paragraph before its own, such as 1.1. and 1.2.:

```csharp
private void outlineButton_Click(object sender, RoutedEventArgs e)
{
    ListFormat outline = new ListFormat(ListType.Structured);
    outline.NumberFormat = NumberFormat.ArabicNumbers;
    outline.TextAfterNumber = ".";
    outline.Level = 2;

    textControl1.Selection.ListFormat = outline;
}
```

The text before and after the numbers of the higher levels is displayed as well.

### Restart the Numbering

Setting `RestartNumbering` to `true` begins a new list at the selected paragraph:

```csharp
private void restartButton_Click(object sender, RoutedEventArgs e)
{
    ListFormat restart = new ListFormat(ListType.Numbered);
    restart.RestartNumbering = true;
    restart.FirstNumber = 1;

    textControl1.Selection.ListFormat = restart;
}
```

The next paragraph a user creates with ENTER inherits the setting and restarts the list again. The blog article [Two Ways to Restart Numbered Lists in TX Text Control](https://www.textcontrol.com/blog/2021/11/03/two-ways-to-restart-numbered-lists/) solves this in code or, more simply, with two list styles.

#### Use List Styles

A "List" style continues the numbering. A "List Restart" style restarts it and has "List" as its following style, so the paragraph after it continues the new list:

```csharp
private void AddListStyles()
{
    ParagraphStyle list = new ParagraphStyle("List");
    list.ListFormat = new ListFormat(ListType.Numbered) { RestartNumbering = false };
    list.FollowingStyle = "List";

    ParagraphStyle restart = new ParagraphStyle("List Restart", "List");
    restart.ListFormat = new ListFormat(ListType.Numbered) { RestartNumbering = true };
    restart.FollowingStyle = "List";

    textControl1.ParagraphStyles.Add(list);
    textControl1.ParagraphStyles.Add(restart);
}
```

Call the method once the control is loaded, for example in its `Loaded` handler, because the style collections are available at run time only. Users apply the styles like any other; [Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/stylesheets/llms-full.txt) explains styles.

### Remove a List

A `ListFormat` of the type `None` takes the selected paragraphs out of their list:

```csharp
textControl1.Selection.ListFormat = new ListFormat(ListType.None);
```

### Read the List Numbers

Displayed numbers aren't part of the paragraph text. [Paragraph.ListNumber](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/paragraph/listnumber-property/llms-full.txt) returns the number of a paragraph, or 0 outside a numbered list, and [ListNumberText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/paragraph/listnumbertext-property/llms-full.txt) returns it with its text before and after. With `using System.Diagnostics;`:

```csharp
private void ShowNumbers()
{
    foreach (TXTextControl.Paragraph paragraph in textControl1.Paragraphs)
    {
        if (paragraph.ListNumber > 0)
        {
            Debug.WriteLine(paragraph.ListNumberText + " " + paragraph.Text);
        }
    }
}
```

To show the list state in your own toolbar, read [BulletedList](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/bulletedlist-property/llms-full.txt), [NumberedList](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/numberedlist-property/llms-full.txt) and [StructuredList](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/structuredlist-property/llms-full.txt) of [InputFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/inputformat-property/llms-full.txt).

### Next Steps

- [Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/stylesheets/llms-full.txt): paragraph styles with list attributes.
- [Text and Paragraph Formatting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/formatting/llms-full.txt): indents, spacing and tab stops.
- [Built-in Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/dialog-boxes/llms-full.txt): the other dialog boxes of the editor.

---

## Nearby

- **Previous:** [Stylesheets](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/stylesheets/llms-full.txt)
- **Next:** [Tables and Table Formulas](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/tables/llms-full.txt)
