其他分享
首页 > 其他分享> > WPF文档介绍(FlowDocument),并做打印输出

WPF文档介绍(FlowDocument),并做打印输出

作者:互联网

一、序论

WPF文档分为两大类,固定文档和流文档。固定文档的容器是DocumentViewer,流文档的容器时FlowDocumentReader、FlowDocumentPageViewer和FlowDocumentScrollViewer,本文主要流文档。

WPF流内容元素构成流文档,它主要由以下2部分组成:

Block元素(块元素)用于分组其他内容元素。

Inline元素(内联元素)被嵌入到块级别元素的内联级别元素

二、Block元素

设置内容元素格式的常用属性:LineHeight:为嵌套的文本内容设置行间距;TextAlignment:为嵌套的文本内容设置水平对齐方式(可以说Left、Right、Center)。

1.Paragraph它表示文本段落,技术上说段落不包含文本--而是包含内联级别元素的集合,存储在Paragraph.Inline集合中。

    <FlowDocumentScrollViewer>
        <FlowDocument>
            <Paragraph>Hello this is China</Paragraph>
            <Paragraph>This is a second paragraph</Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>

 

2.List元素表示项目符号或数字列表,可以通过MarkerStyle属性进行选择。

            <Paragraph>Top program language</Paragraph>
            <List>
                <ListItem>
                    <Paragraph>C#</Paragraph>
                    <Paragraph>C++</Paragraph>
                </ListItem>
            </List>
            <Paragraph>To-do List</Paragraph>
            <List MarkerStyle="Decimal">
                <ListItem>
                    <Paragraph>WPF</Paragraph>                   
                </ListItem>
                <ListItem>
                    <Paragraph>Winform</Paragraph>
                </ListItem>
            </List>

3.Table元素

<Table BorderBrush="Black" BorderThickness="1">
                <Table.Columns>
                    <TableColumn Width="*"/>
                    <TableColumn Width="3*"/>
                    <TableColumn Width="*"/>
                </Table.Columns>
                <TableRowGroup Paragraph.TextAlignment="Left">
                    <TableRow FontWeight="Bold">
                        <TableCell BorderBrush="Black" BorderThickness="1">
                            <Paragraph>Rank</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Name</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Population</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell>
                            <Paragraph>1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Rome</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>1000000</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell>
                            <Paragraph>1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Luoyang(HuNan),China</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>3210000</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell>
                            <Paragraph>1</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>Peshawar,pkeuysd</Paragraph>
                        </TableCell>
                        <TableCell>
                            <Paragraph>1003400</Paragraph>
                        </TableCell>
                    </TableRow>
                </TableRowGroup>
            </Table>
View Code

注:在没有为列提供明确的宽度时,wpf将为所有列平均分配空间。

4.Section元素

Section元素本身没有任何内置的格式化设置,而是用于在某个方便的包中封装其他块级别元素,方便为整个部分应用常用格式。          

<Section FontSize="20" Background="RED" Paragraph.LineHeight="1">
<Paragraph>this is first paragraph</Paragraph>
<Paragraph>this is second paragraph</Paragraph>
</Section>

5.BlockUIContainer元素

用来放控件。

        <BlockUIContainer>
                <Button HorizontalAlignment="Left" Name="hhhh" Content="this is BlockUIContainer"/>
            </BlockUIContainer>

三、内联元素

1.Floater

标签:打印输出,FlowDocument,Section,元素,Paragraph,文档,内联,WPF
来源: https://www.cnblogs.com/yxzstruggle/p/15414670.html