Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Lists

A list represents a set of properties which are used to describe the appearance and behavior of a set of numbered paragraphs. All lists are stored in ListCollection accessible through RadFlowDocument's Lists property.

List Overview

The class containing the structure corresponding to a list is List and exposes the following properties:

  • StyleId: A string property, which specifies the numbering style associated with the list.

  • Levels: Represents a collection of ListLevel objects. Every list can contain up to 9 levels.

  • MultilevelType: The type of the list, described with the MultilevelType enumeration. It defines the behavior of the list.

To insert commonly used types of lists like bullet or numbered lists, list templates can be used.

List Types

The type of the list is used by an application to determine the user interface behavior for a list and in RadWordsProcessing's model is represented by the MultilevelType enumeration. The possible types are:

  • HybridMultilevel: Specifies that the list can contain multiple levels, each from potentially different type – bullet, decimal, letter, etc. This is the default MultilevelType value.

  • Multilevel: Specifies that the list can contain multiple levels, each of the same type.

  • SingleLevel: Specifies that only level 1 of the list should be used, all other levels are ignored. When a list has MultilevelType.SingleLevel, you should apply the desired list level properties only on the first list level in the List's Levels collection.

ListLevel Overview

ListLevel is the class containing the structure of the list levels. It describes a set of properties, which specify the appearance and behavior of the associated numbered paragraph.

  • StartIndex: Specifies the starting number of a ListLevel. The value should be equal or greater than 0.

  • RestartAfterLevel: Indicates the list level which should restart the current level to its start index. The value must be higher (earlier than this level), the possible values are between 0 and 8 inclusive.

  • NumberTextFormat: Specifies the number format string for a list level.

  • NumberingStyle: The numbering style of a list level, described with the NumberingStyle enumeration . It can be a number, bullet, letter, etc. The default value is NumberingStyle.Bullet.

  • IsLegal: Specifies if all inherited number formats should be displayed as NumberingStyle.Decimal format. If the value is true, then all numbering levels in the current ListLevel shall be converted to their corresponding decimal values. If the value is false, they shall be displayed in the string format set by the NumberTextFormat property.

  • StyleId: Specifies the name of the paragraph style associated with the list level. ListLevel can be associated only with a paragraph style.

  • Alignment: Specifies the alignment of content in this level.

  • CharacterProperties: Represents the associated character properties.

  • ParagraphProperties: Represents the associated paragraph properties.

List Templates

There are a set of commonly used lists which are predefined for convenience and are called list templates. All available templates are within the ListTemplateType enumeration.

In order to add one of the list templates to the document, you need to pass a ListTemplateType value to the ListCollection.Add() method. This would add the required template to the document and return the resulting list.

Example 1 adds a default bulleted list to a predefined RadFlowDocument.

Example 1: Add list template

List list = document.Lists.Add(ListTemplateType.BulletDefault); 

Create a List

The next tutorial will get you through the creation of a list.

  1. Define a new RadFlowDocument and add a Section in it.

    Step 1: Create RadFlowDocument

        RadFlowDocument document = new RadFlowDocument(); 
        Section section = document.Sections.AddSection(); 
    
  2. Create a List object and associate it with the document by adding it to the Lists collection.

    Step 2: Create list

        List list = new List(); 
        document.Lists.Add(list); // Adding the list in the document. 
    

    In this case, the default HybridMultilevel type of list would be created.
  3. Iterate over the collection of Levels the list has.

    Step 3: Iterate levels

        for (int level = 0; level < list.Levels.Count; ++level) 
    
  4. Specify some properties for each level.

    Step 4: Customize list levels

        bool isEven = (level % 2) == 0; 
     
        list.Levels[level].StartIndex = 1; 
        // We set Decimal numbering style to a list level if it is even level, otherwise Bullet. 
        list.Levels[level].NumberingStyle = isEven ? NumberingStyle.Decimal : NumberingStyle.Bullet; 
        // Accordingly to the above rule, we set the corresponding NumberTextFormat. 
        list.Levels[level].NumberTextFormat = isEven ? "%" + (level + 1) + "." : "o"; 
        // Set the desired indentation of the ListLevel can be done through its ParagraphProperties: 
        list.Levels[level].ParagraphProperties.LeftIndent.LocalValue = 48 + (level * 24); 
    

    With this step the list is ready-to-use.

Apply List

The tutorial in the previous section demonstrates how you can create a List. Once the list has been created you can apply it to a set of paragraphs by setting the ListId property of the paragraphs to the Id of the list.

Example 6 demonstrates how you can apply the list created in Steps 1-4 above.

Example 6: Apply list

for (int level = 0; level < list.Levels.Count; level++) 
{ 
    Paragraph paragrah = section.Blocks.AddParagraph(); 
    paragrah.Inlines.AddRun(string.Format("ListLevel: {0}", level + 1)); 
    paragrah.ListId = list.Id; 
    paragrah.ListLevel = level; 
} 

Figure 1: Result of Example 6

Rad Words Processing Concepts Lists 01

See Also

In this article