列表到ListItem以创建新的MarkerStyle Bullet

时间:2012-02-03 05:50:48

标签: wpf

我如何使用代码执行此操作?

<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>
</List>
</FlowDocument>

具体是:

<Paragraph>Boron</Paragraph>
  <List Margin="0" Padding="0"  >

这一部分。

1 个答案:

答案 0 :(得分:1)

从MSDN页面@Clemens添加了一个指向List class的链接:

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);

注意创建ListItem的位置。每个ListItem都使用一个新的Paragraph对象构造,该对象由一个新的Run对象构成,该对象又由一个文本字符串构成。这是您在代码中向Paragraph添加文本的方法。在XAML中,WPF框架隐式添加了Run对象,尽管您也可以明确声明它们。

<Paragraph>
    <Run>Boron</Run>
</Paragraph>