2012-01-18 65 views
0

下面是來自默認WPF應用程序的MainWindow.xaml的示例代碼。文檔中的第一個和最後一個'塊'是段落,中間是一個表格。表格總是出現在其列的左邊緣,表格右邊的區域是空白的。我想把桌子放在這個空間中。如何在一個FlowDocument中水平居中表或列表?

我曾嘗試將表格放在'Section','Paragraph'等內,但沒有任何運氣。段落內的Floater工作,但隨後表格會流入下一段。也許我可以通過左右兩個空列來動態計算它們的寬度,但看起來有點過分。

感謝 Jeevaka

<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> 

回答

0

有你想圍繞一個集裝箱就像一個網格或境內感興趣的元素,並設置爲Center WPF做其餘的屬性稱爲HorizontalAlignment一個WPF元素屬性魔術。