PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 18, 2022

[FIXED] How can I vertically align a TableCell (or its content) of a FlowDocument

 November 18, 2022     flowdocument, vertical-alignment, wpf, xaml     No comments   

Issue

Is there any way to align the content of a TableCell to the bottom? I thought this was easy, but obviously, it is not.

The situation:

Inside a FlowDocument I have the following (simplified) 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>

The two images do not have the same height so there is some empty space below the smaller of them.

What I want:

Instead, I want the empty space above the smaller image (i.e. the images aligned to the bottom of the TableRow).

What I tried:

I tried to find a VerticalAlignment property to change the alignment. However, there is no VerticalAlignment property in BlockUIContainer, TableCell or TableRow.

Also, I tried replacing the BlockUIContainer by an InlineUIContainer and setting its BaselineAlignment. However, to do this, I had to wrap it into a Paragraph like so:

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

Now I have an image aligned to the bottom of a Paragraph which is aligned to the top of the TableCell and only as high as required for the Image. So it looks exactly as it did before.


Solution

The only way to do this in my experience is to use a grid to format an entire table row. Use the grid to create columns, not the table. Therefore you can use the capabilities of the grid to bottom align your images. Here is what your table might look like now...

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


Answered By - AQuirky
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing