Lists
A list represents a set of properties that describe the appearance and behavior of a set of numbered paragraphs. All lists are stored in the ListCollection accessible through the Lists property of RadFlowDocument.
List Overview
The class that contains the structure corresponding to a list is List and exposes the following properties:
-
StyleId: A string property that 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 the RadWordsProcessing model is represented by the MultilevelType enumeration. The possible types are:
-
HybridMultilevel: Specifies that the list can contain multiple levels, each from a potentially different type—bullet, decimal, letter, and more. This is the defaultMultilevelTypevalue. -
Multilevel: Specifies that the list can contain multiple levels, each of the same type. -
SingleLevel: Specifies that only level 1 of the list is used. All other levels are ignored. When a list hasMultilevelType.SingleLevel, apply the desired list level properties only on the first list level in theLevelscollection of theList.
ListLevel Overview
ListLevel is the class containing the structure of the list levels. It describes a set of properties that specify the appearance and behavior of the associated numbered paragraph.
-
StartIndex: Specifies the starting number of aListLevel. The value must be equal to or greater than 0. -
RestartAfterLevel: Indicates the list level which restarts 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, and more. The default value isNumberingStyle.Bullet. -
IsLegal: Specifies if all inherited number formats display asNumberingStyle.Decimalformat. If the value istrue, all numbering levels in the currentListLevelare converted to their corresponding decimal values. If the value isfalse, they display in the string format set by theNumberTextFormatproperty. -
StyleId: Specifies the name of the paragraph style associated with the list level.ListLevelcan 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 that are predefined for convenience and are called list templates. All available templates are within the ListTemplateType enumeration.
To add one of the list templates to the document, pass a ListTemplateType value to the ListCollection.Add() method. This adds the required template to the document and returns the resulting list.
The following example 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 following tutorial walks you through the creation of a list.
-
Define a new
RadFlowDocumentand add aSectionin it.Step 1: Create RadFlowDocument
C#RadFlowDocument document = new RadFlowDocument(); Section section = document.Sections.AddSection(); -
Create a
Listobject and associate it with the document by adding it to theListscollection.Step 2: Create List
C#List list = new List(); document.Lists.Add(list); // Adding the list in the document.In this case, the default
HybridMultileveltype of list is created. -
Iterate over the collection of
Levelsthe list has.Step 3: Iterate Levels
C#for (int level = 0; level < list.Levels.Count; ++level) -
Specify some properties for each level.
Step 4: Customize List Levels
C#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. After you create the list, you can apply it to a set of paragraphs by setting the ListId property of the paragraphs to the Id of the list.
The following example demonstrates how you can apply the list created in Steps 1–4.
Example 6: Apply List
for (int level = 0; level < list.Levels.Count; level++)
{
Paragraph paragraph = section.Blocks.AddParagraph();
paragraph.Inlines.AddRun(string.Format("ListLevel: {0}", level + 1));
paragraph.ListId = list.Id;
paragraph.ListLevel = level;
}
Figure 1: Result of Example 6
