Wpf 如何在FlowDocument中水平居中放置表格或列表?

Wpf 如何在FlowDocument中水平居中放置表格或列表?,wpf,xaml,flowdocument,Wpf,Xaml,Flowdocument,下面是来自默认WPF应用程序MainWindow.xaml的示例代码。文档中的第一个和最后一个“块”是段落,中间的一个是表格。表格始终显示在其列的左边缘,表格右侧的区域为空白。我想把桌子放在这个地方的中间 我试着把桌子放在一个“部分”和一个“段落”中,但没有成功。段落中的浮动框起作用,但随后表格将流入下一段。也许我可以通过使用左右两侧的两个空列来动态计算它们的宽度,但这看起来有些过分了 谢谢 吉瓦卡 土星卫星 土星的卫星数量众多,种类繁多,从直径不到1公里的小卫星到比水星还大的巨大土卫六。土星

下面是来自默认WPF应用程序MainWindow.xaml的示例代码。文档中的第一个和最后一个“块”是段落,中间的一个是表格。表格始终显示在其列的左边缘,表格右侧的区域为空白。我想把桌子放在这个地方的中间

我试着把桌子放在一个“部分”和一个“段落”中,但没有成功。段落中的浮动框起作用,但随后表格将流入下一段。也许我可以通过使用左右两侧的两个空列来动态计算它们的宽度,但这看起来有些过分了

谢谢 吉瓦卡


土星卫星
土星的卫星数量众多,种类繁多,从直径不到1公里的小卫星到比水星还大的巨大土卫六。土星有62颗卫星,其轨道已确定,其中53颗有名字,其中只有13颗直径大于50公里。土星有七颗卫星,它们足够大,可以变成球形,还有密集的环,它们自身的轨道运动非常复杂。在土星的卫星中尤其引人注目的是土卫六,土卫六是太阳系第二大卫星,有着类似地球的富氮大气和包括碳氢化合物湖泊和干涸河流网络在内的景观,而土卫二则发射出气体和尘埃喷流,可能在其南极地区藏有液态水。
名称
直径
米马斯
396
土卫二
504
特提斯
1062
土星的卫星中有24颗是常规卫星;它们的前进轨道不太倾向于土星的赤道面。它们包括七颗主要卫星、四颗存在于特洛伊轨道上的小卫星和较大的卫星、两颗相互共轨的卫星以及两颗充当土星F环守护者的卫星。另外两颗已知的常规卫星在土星环的间隙内运行。相对较大的Hyperion与土卫六发生共振。其余的规则卫星在A环外缘附近、G环内以及主卫星米马斯和土卫二之间运行。常规卫星传统上是以土卫六和土卫六或其他与神话中的土星有关的人物命名的。

有一个名为
HorizontalAlignment
的WPF元素属性,您希望将感兴趣的元素包围在一个容器中,如网格或边框,并将该属性设置为
Center
WPF完成其余的工作

<Window x:Class="FlowDocument.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="700" Width="700">
    <FlowDocumentPageViewer>
        <FlowDocument>
            <Paragraph FontSize="24">Moons of Saturn</Paragraph>
            <Paragraph>The moons of Saturn are numerous and diverse, ranging from tiny moonlets less than 1 kilometre across, to the enormous Titan, which is larger than the planet Mercury. Saturn has 62 moons with confirmed orbits, fifty-three of which have names, and only thirteen of which have diameters larger than 50 kilometres. Saturn has seven moons that are large enough to become spherical, and dense rings with complex orbital motions of their own. Particularly notable among Saturn's moons are Titan, the second largest moon in the Solar System, with a nitrogen-rich Earth-like atmosphere and a landscape including hydrocarbon lakes and dry river networks, and Enceladus, which emits jets of gas and dust and may harbor liquid water under its south pole region.</Paragraph>
            <Table TextAlignment="Right" BorderBrush="Black" BorderThickness="1" Background="Black">
                <Table.Columns>
                    <TableColumn Width="100" ></TableColumn>
                    <TableColumn Width="100"></TableColumn>
                </Table.Columns>
                <TableRowGroup>
                    <TableRow>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>Name</Paragraph>
                        </TableCell>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>Diameter</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>Mimas</Paragraph>
                        </TableCell>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>396</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>Enceladus</Paragraph>
                        </TableCell>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>504</Paragraph>
                        </TableCell>
                    </TableRow>
                    <TableRow>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>Tethys</Paragraph>
                        </TableCell>
                        <TableCell Background="White" Padding="5">
                            <Paragraph>1062</Paragraph>
                        </TableCell>
                    </TableRow>
                </TableRowGroup>
            </Table>
            <Paragraph>Twenty-four of Saturn's moons are regular satellites; they have prograde orbits not greatly inclined to Saturn's equatorial plane. They include the seven major satellites, four small moons which exist in a Trojan orbit with larger moons, two mutually co-orbital moons and two moons which act as shepherds of Saturn's F Ring. Two other known regular satellites orbit within gaps in Saturn's rings. The relatively large Hyperion is locked in a resonance with Titan. The remaining regular moons orbit near the outer edge of the A Ring, within G Ring and between the major moons Mimas and Enceladus. The regular satellites are traditionally named after Titans and Titanesses or other figures associated with the mythological Saturn.</Paragraph>
        </FlowDocument>
    </FlowDocumentPageViewer>
</Window>