List Class

A list in a document.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v21.2.dll

Declaration

public class List

Remarks

A List object contains settings of a list in a document. A list is a series of paragraphs. Each paragraph contains information about the list (ListIndex) and the list level (ListLevelIndex) to which it belongs.

The image below shows a list that consists of five paragraphs.

Rich Edit - List

A List object contains a collection of nine ListLevel objects - one for each possible level of the list. A ListLevel object contains style settings that are applied to paragraphs of the corresponding list level.

Create a List

A document’s Lists property returns a collection of document lists. The collection implements the CreateAsync(ListType) method, which allows you to initialize a new list of the specified type in the document.

<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            @* ... *@
            List list = await documentAPI.Lists.CreateAsync(ListType.MultiLevel);
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

After you have initialized a new list, you can add paragraphs to the list and modify list properties.

Add Paragraphs to a List

Call a paragraph’s AddToListAsync(List, Int32) method to set the paragraph’s ListIndex and ListLevel properties, apply a list format style to the paragraph, and add the paragraph to the list.

The following code sample adds every paragraph in the main sub-document to the first level of the list:

<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            @* ... *@
            List list = await documentAPI.Lists.CreateAsync(ListType.MultiLevel);
            @* ... *@
            IReadOnlyList<Paragraph> paragraphs = await documentAPI.Paragraphs.GetAllAsync();
            foreach (Paragraph p in paragraphs) {
                await p.AddToListAsync(list, 0);
            }
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

Remove Paragraphs from a List

Call the RemoveFromListAsync() method to set the paragraph’s ListIndex and ListLevelIndex properties to null, remove the list format style from the paragraph, and remove the paragraph from the list.

The following code sample removes every paragraph in the main sub-document from a list.

<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            @* ... *@
            paragraphs = await documentAPI.Paragraphs.GetAllAsync();
            foreach (Paragraph p in paragraphs)
                if (p.ListIndex != null)
                    await p.RemoveFromListAsync();
                    @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

Modify List Properties

When you create a new List object, the Rich Text Editor populates the List.ListLevels collection with nine pre-defined ListLevel objects. Each object contains style settings that are applied to paragraphs of the corresponding list level. The initial list level settings depend on the type of the list (numbered, bulleted, or multilevel).

Call the ChangeLevelPropertiesAsync(Int32, Action<ListLevelProperties>) method to change a list level’s style settings.

<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            @* ... *@
            // Initializes a list 
            List list = await documentAPI.Lists.CreateAsync(ListType.MultiLevel);
            // Sets style settings for the 0 list level's paragraphs
            await list.ChangeLevelPropertiesAsync(0, properties => {
                properties.DisplayFormatString = "{0}";
                properties.FirstLineIndent = 500;
                properties.FirstLineIndentType = FirstLineIndentType.Indented;
                properties.FontBold = true;
                properties.FontColor = System.Drawing.Color.DarkBlue;
                properties.FontItalic = true;
                properties.FontName = "Arial";
                properties.FontSize = 16;
                properties.LeftIndent = 200;
                properties.ListLevelFormat = ListLevelFormat.Decimal;
                properties.Separator = " ";
                properties.Start = 1;
            });
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

Inheritance

Object
List
See Also