c# - FlowDocument 的网格替代方案?
问题描述
根据我的阅读,不能在 FlowDocument 中使用 Grid。
<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>
输出:
现在的问题是,如果我填写Textblock's
第二个 StackPanel,如果它们很长,它们将不会显示所有文本,这是预期的,因为我已经为它们设置了特定的宽度。如果我将其设置为Auto
它将显示,但每个内容都Textblock
不会与列对齐,并且会更混乱。
我目前的选择是什么?
解决方案
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>
你可以在这里找到更多信息。我希望它可以帮助你。
推荐阅读
- python - 提高性能 cv2.calibrateCamera
- ansible - 将厨师食谱部分转换为 ansible
- netflix-eureka - 使用 EurekaHttpClient 手动注册服务时获取 http 代码状态 400
- java - Java combining ArrayList contains() and ArrayList remove()
- excel - 在 excel 中删除/清除表格内容但保留最后三列的宏
- react-native - 如果查询已在应用程序启动时执行,则无法在 React Native (Expo) 中运行 SQLite 查询
- javascript - 设置 maxDate 时防止自动选择日期 - Material UI React JS
- python - 根据用户输入确定的列过滤数据框
- sql - 获取每年最受欢迎的五个名字的总和 | 大查询
- visual-studio-code - vscode rust 自动补全不完整