Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ListItem Class
Collapse the table of content
Expand the table of content

ListItem Class

A flow content element that represents a particular content item in an ordered or unordered List.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[ContentPropertyAttribute("Blocks")]
public class ListItem : TextElement
<ListItem>
  Blocks
</ListItem>

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

ListItem elements must be contained by 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 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2015 Microsoft