2016-12-15 118 views
3

有什麼辦法可以將TableCell的內容與底部對齊?我認爲這很容易,但很明顯,事實並非如此。如何垂直對齊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屬性來更改對齊。但是,BlockUIContainer,TableCellTableRow中沒有VerticalAlignment財產。

此外,我試圖用InlineUIContainer替換BlockUIContainer並將其設置爲BaselineAlignment。然而,要做到這一點,我不得不把它包裝成一個Paragraph像這樣:

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

現在我有一個圖像對準它對準TableCell頂部只有一樣高Paragraph底部Image需要。所以它看起來和以前一樣。

回答

1

以我的經驗做到這一點的唯一方法是使用網格來格式化整個表格行。使用網格創建列,而不是表格。因此,您可以使用網格的功能來對齊圖像。這裏是你的桌子現在看起來像什麼...

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

太棒了,謝謝!我只需要將'ColumnSpan = 3'添加到'TableCell'來獲得正確的列。 – wkl