Export (0) Print
Expand All

List Class

A block-level flow content element that provides facilities for presenting content in an ordered or unordered list.

Namespace: System.Windows.Documents
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[ContentPropertyAttribute("ListItems")] 
public class List : Block
/** @attribute ContentPropertyAttribute("ListItems") */ 
public class List extends Block
ContentPropertyAttribute("ListItems") 
public class List extends Block
<List>
  ListItems
</List>

Content Model: List enforces a strong content model for child content. See TextElement Content Model Overview for more information about the List content model.

List is a flow content element designed to be formatted with markers such as bullets or numbering.

ListItem elements are the only permissible children for a List element.

The following example shows how to define a List using XAML.

<FlowDocument Background="GhostWhite">
  <List MarkerOffset="25" MarkerStyle="UpperRoman" StartIndex="5">
    <ListItem>
      <Paragraph>Boron</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Carbon</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Nitrogen</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Oxygen</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Fluorine</Paragraph>
    </ListItem>
    <ListItem>
      <Paragraph>Neon</Paragraph>
    </ListItem>
  </List>
</FlowDocument>

The following example shows how to create and populate a List programmatically.

List listx = new List();
// Set the space between the markers and list content to 25 DIP.
listx.MarkerOffset = 25;
// Use uppercase Roman numerals.
listx.MarkerStyle = TextMarkerStyle.UpperRoman;
// Start list numbering at 5.
listx.StartIndex = 5;

// Create the list items that will go into the list.
ListItem liV = new ListItem(new Paragraph(new Run("Boron")));
ListItem liVI = new ListItem(new Paragraph(new Run("Carbon")));
ListItem liVII = new ListItem(new Paragraph(new Run("Nitrogen")));
ListItem liVIII = new ListItem(new Paragraph(new Run("Oxygen")));
ListItem liIX = new ListItem(new Paragraph(new Run("Fluorine")));
ListItem liX = new ListItem(new Paragraph(new Run("Neon")));

// Finally, add the list items to the list.
listx.ListItems.Add(liV);
listx.ListItems.Add(liVI);
listx.ListItems.Add(liVII);
listx.ListItems.Add(liVIII);
listx.ListItems.Add(liIX);
listx.ListItems.Add(liX);

The following figure shows how this example renders.

Screenshot: Ordered list

The following example shows how to define a nested List (lists within lists) using XAML.

<FlowDocument Background="GhostWhite">
  <List MarkerOffset="25" MarkerStyle="UpperRoman" StartIndex="5">
    <ListItem>
      <Paragraph>Boron</Paragraph>
      <List Margin="0" Padding="0"  >
        <ListItem Margin="40,0,0,0">
          <Paragraph>Symbol: B</Paragraph>
        </ListItem>
        <ListItem Margin="40,0,0,0">
          <Paragraph>Atomic Mass: 10.811</Paragraph>
        </ListItem>
      </List>
    </ListItem>
    <ListItem>
      <Paragraph>Carbon</Paragraph>
      <List Margin="0" Padding="0"  >
        <ListItem Margin="40,0,0,0">
          <Paragraph>Symbol: C</Paragraph>
        </ListItem>
        <ListItem Margin="40,0,0,0">
          <Paragraph>Atomic Mass: 12.0107</Paragraph>
        </ListItem>
      </List>
    </ListItem>
    <ListItem>
      <Paragraph>Nitrogen</Paragraph>
      <List Margin="0" Padding="0"  >
        <ListItem Margin="40,0,0,0">
          <Paragraph>Symbol: N</Paragraph>
        </ListItem>
        <ListItem Margin="40,0,0,0">
          <Paragraph>Atomic Mass: 14.00674</Paragraph>
        </ListItem>
      </List>
    </ListItem>
    <ListItem>
      <Paragraph>Oxygen</Paragraph>
        <List Margin="0" Padding="0"  >
          <ListItem Margin="40,0,0,0">
            <Paragraph>Symbol: O</Paragraph>
          </ListItem>
          <ListItem Margin="40,0,0,0">
            <Paragraph>Atomic Mass: 15.9994</Paragraph>
          </ListItem>
        </List>
    </ListItem>
    <ListItem>
      <Paragraph>Fluorine</Paragraph>
      <List Margin="0" Padding="0"  >
        <ListItem Margin="40,0,0,0">
          <Paragraph>Symbol: F</Paragraph>
        </ListItem>
        <ListItem Margin="40,0,0,0">
          <Paragraph>Atomic Mass: 18.9984032</Paragraph>
        </ListItem>
      </List>
    </ListItem>
    <ListItem>
      <Paragraph>Neon</Paragraph>
      <List Margin="0" Padding="0"  >
        <ListItem Margin="40,0,0,0">
          <Paragraph>Symbol: Ne</Paragraph>
        </ListItem>
        <ListItem Margin="40,0,0,0">
          <Paragraph>Atomic Mass: 20.1797</Paragraph>
        </ListItem>
      </List>
    </ListItem>
  </List>
</FlowDocument>

The following figure shows how this example renders.

Nested list

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft