如何垂直对齐FlowDocument的TableCell(或其内容)

时间:2016-12-15 11:00:33

标签: wpf xaml vertical-alignment flowdocument

有没有办法将TableCell的内容与底部对齐?我觉得这很容易,但显然不是。

情况:

FlowDocument内,我有以下(简化)Table

<Table>
    <Table.Columns>
        <TableColumn Width="Auto"/>
        <TableColumn Width="Auto"/>
        <TableColumn Width="Auto"/>
    </Table.Columns>
    <TableRowGroup>
        <TableRow>
            <TableCell>
                <BlockUIContainer>
                    <Image Source="{Binding to an image}"/>
                </BlockUIContainer>
            </TableCell>
            <TableCell containing something else/>
           <TableCell>
                <BlockUIContainer>
                    <Image Source="{Binding to another image}"/>
                </BlockUIContainer>
            </TableCell>
        </TableRow>
    </TableRowGroup>
</Table>

这两个图像的高度不同,因此在较小的图像下方有一些空白区域。

我想要的是什么:

相反,我希望上面的空白是较小的图像(即图像与TableRow的底部对齐)。

我尝试了什么:

我试图找到VerticalAlignment属性来更改对齐方式。但是,VerticalAlignmentBlockUIContainerTableCell中没有TableRow属性。

此外,我尝试将BlockUIContainer替换为InlineUIContainer并设置其BaselineAlignment。但是,要做到这一点,我必须将它包装成Paragraph,如此:

<TableCell>
    <Paragraph>
        <InlineUIContainer BaselineAlignment="Bottom">
            <Image Source="{Binding to an image}"/>
        </InlineUIContainer>
    </Paragraph>
</TableCell>

现在,我的图片与Paragraph的底部对齐,该图片与TableCell的顶部对齐,且只有Image所需的高度。所以看起来和以前完全一样。

1 个答案:

答案 0 :(得分:2)

根据我的经验,这样做的唯一方法是使用网格格式化整个表格行。使用网格创建列,而不是表。因此,您可以使用网格的功能来对齐图像。这是你的桌子现在的样子......

    <Table>
        <TableRowGroup>
            <TableRow>
                <TableCell>
                    <BlockUIContainer>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Image Grid.Column="0" Source="Images/globe.png" Height="10" Width="10" VerticalAlignment="Bottom"/>
                            <TextBlock Grid.Column="1" TextWrapping="Wrap">This is something else</TextBlock>
                            <Image Grid.Column="2" Source="Images/globe.png" Height="20" Width="20" VerticalAlignment="Bottom"/>
                        </Grid>
                    </BlockUIContainer>
                </TableCell>
            </TableRow>
        </TableRowGroup>
    </Table>