简体   繁体   中英

How to set the vertical alignment of a System.Windows.Documents.TableCell?

In my program with C# I use a System.Windows.Documents.Table. When I want to set the vertical alignment of TableCell, I found I cannot. It only provides a TextAlignment property which can only set the horizontal alignment of text content. Is there any method to set its vertical alignment ? I'll be appreciative for this.

Because there is more than one TableCell in one TableRow. It is different to this situation . My solution is to traverse every tablerow, and in every tablerow i traverse every tablecell in it, calculate the max height in them as the height of the row, then set tablecell's padding according to the max height. Here is the method to get the rowheight:

private double getRowHeight(TableRow row)
    {
        double maxHeight = 0;
        foreach (TableCell cell in row.Cells)
        {
            Rect startRect = cell.ElementStart.GetCharacterRect(LogicalDirection.Forward);
            Rect endRect = cell.ElementEnd.GetNextInsertionPosition(LogicalDirection.Backward).GetCharacterRect(LogicalDirection.Forward);
            double Height = (endRect.Bottom - startRect.Top);
            maxHeight = maxHeight > Height ? maxHeight : Height;
        }
        return maxHeight;
    }

It seems not so elegant. But it's the only method i can figure out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM