据我了解,Grid在FlowDocument内部无法使用。
<TextBlock Margin="0 10" FontFamily="Ubuntu" FontSize="19" FontWeight="DemiBold" Text="Account details"></TextBlock>
<Separator Width="600"></Separator>
<StackPanel Margin="0 10" Orientation="Horizontal">
<TextBlock Margin="0 0 30 0" Text="Account ID"></TextBlock>
<TextBlock Margin="0 0 30 0" Text="Username"></TextBlock>
<TextBlock Margin="0 0 30 0" Text="Password"></TextBlock>
<TextBlock Margin="0 0 30 0" Text="Creation date"></TextBlock>
</StackPanel>
<Separator Width="600"></Separator>
<StackPanel Margin="0 10" Orientation="Horizontal">
<TextBlock Width="102" Margin="0 0 30 0" ></TextBlock>
<TextBlock Width="Auto" Margin="0 0 30 0" ></TextBlock>
<TextBlock Width="Auto" Margin="0 0 30 0" ></TextBlock>
<TextBlock Width="91" Margin="0 0 30 0" ></TextBlock>
</StackPanel>
</StackPanel>
输出:
现在的问题是,如果我在第二个StackPanel中填充Textblock's
,它们将不会显示所有文本(如果它们很长),这是预期的,因为我为它们设置了特定的宽度。如果将其设置为Auto
,它将显示,但是每个Textblock
的内容都不会与列对齐,并且会变得更混乱。
我当前有哪些选择?
答案 0 :(得分:0)
如果您想在FlowDocument
中创建一种网格(即您要绘制表格),则可以使用Table类。它源自Block元素,因此可以包含在FlowDocument
中。
Table
非常易于使用:
<FlowDocument>
<Table>
<!--
This table has 3 columns, each described by a TableColumn
element nested in a Table.Columns collection element.
-->
<Table.Columns>
<TableColumn />
<TableColumn />
<TableColumn />
</Table.Columns>
<!--
This table includes a single TableRowGroup which hosts 2 rows,
each described by a TableRow element.
-->
<TableRowGroup>
<!--
Each of the 2 TableRow elements hosts 3 cells, described by
TableCell elements.
-->
<TableRow>
<TableCell>
<!--
TableCell elements may only host elements derived from Block.
In this example, Paragaph elements serve as the ultimate content
containers for the cells in this table.
-->
<Paragraph>Cell at Row 1 Column 1</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Cell at Row 1 Column 2</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Cell at Row 1 Column 3</Paragraph>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Paragraph>Cell at Row 2 Column 1</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Cell at Row 2 Column 2</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Cell at Row 2 Column 3</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</FlowDocument>
您可以找到更多信息here。 希望它能对您有所帮助。