ListLevelCollection Class

A collection of list formatting for each level in a list.

Inheritance Hierarchy

SystemObject
  Aspose.Words.ListsListLevelCollection

Namespace:  Aspose.Words.Lists
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public class ListLevelCollection : IEnumerable<ListLevel>, 
	IEnumerable

The ListLevelCollection type exposes the following members.

Properties

  NameDescription
Public propertyCode exampleCount
Gets the number of levels in this list.
Public propertyCode exampleItem
Gets a list level by index.

Methods

  NameDescription
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetEnumerator
Gets the enumerator object that will enumerate levels in this list.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)

Examples

Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
Document doc = new Document();

// Create a list based on one of the Microsoft Word list templates
List list = doc.Lists.Add(ListTemplate.NumberDefault);

// Completely customize one list level
ListLevel listLevel = list.ListLevels[0];
listLevel.Font.Color = Color.Red;
listLevel.Font.Size = 24;
listLevel.NumberStyle = NumberStyle.OrdinalText;
listLevel.StartAt = 21;
listLevel.NumberFormat = "\x0000";

listLevel.NumberPosition = -36;
listLevel.TextPosition = 144;
listLevel.TabPosition = 144;

// Customize another list level
listLevel = list.ListLevels[1];
listLevel.Alignment = ListLevelAlignment.Right;
listLevel.NumberStyle = NumberStyle.Bullet;
listLevel.Font.Name = "Wingdings";
listLevel.Font.Color = Color.Blue;
listLevel.Font.Size = 24;
listLevel.NumberFormat = "\xf0af"; // A bullet that looks like a star
listLevel.TrailingCharacter = ListTrailingCharacter.Space;
listLevel.NumberPosition = 144;

// Now add some text that uses the list that we created
// It does not matter when to customize the list - before or after adding the paragraphs
DocumentBuilder builder = new DocumentBuilder(doc);

builder.ListFormat.List = list;
builder.Writeln("The quick brown fox...");
builder.Writeln("The quick brown fox...");

builder.ListFormat.ListIndent();
builder.Writeln("jumped over the lazy dog.");
builder.Writeln("jumped over the lazy dog.");

builder.ListFormat.ListOutdent();
builder.Writeln("The quick brown fox...");

builder.ListFormat.RemoveNumbers();

builder.Document.Save(ArtifactsDir + "Lists.CreateCustomList.docx");
Shows how to create a list style and use it in a document.
Document doc = new Document();

// Create a new list style
// List formatting associated with this list style is default numbered
Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");

// This list defines the formatting of the list style
// Note this list can not be used directly to apply formatting to paragraphs (see below)
List list1 = listStyle.List;

// Check some basic rules about the list that defines a list style
Assert.True(list1.IsListStyleDefinition);
Assert.False(list1.IsListStyleReference);
Assert.True(list1.IsMultiLevel);
Assert.AreEqual(listStyle, list1.Style);

// Modify formatting of the list style to our liking
foreach (ListLevel level in list1.ListLevels)
{
    level.Font.Name = "Verdana";
    level.Font.Color = Color.Blue;
    level.Font.Bold = true;
}

// Add some text to our document and use the list style
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Using list style first time:");

// This creates a list based on the list style
List list2 = doc.Lists.Add(listStyle);

// Check some basic rules about the list that references a list style
Assert.False(list2.IsListStyleDefinition);
Assert.True(list2.IsListStyleReference);
Assert.AreEqual(listStyle, list2.Style);

// Apply the list that references the list style
builder.ListFormat.List = list2;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();

builder.Writeln("Using list style second time:");

// Create and apply another list based on the list style
List list3 = doc.Lists.Add(listStyle);
builder.ListFormat.List = list3;
builder.Writeln("Item 1");
builder.Writeln("Item 2");
builder.ListFormat.RemoveNumbers();

builder.Document.Save(ArtifactsDir + "Lists.CreateAndUseListStyle.docx");

See Also