我如何使用代码执行此操作?
<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" >
这一部分。
答案 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>