Question

It possible vertical align text in TableColumn on middle?

I add paragraph to the table cell of table. And this table I add to richTexBox control. Problem is that middle column consists of images(emoticons) and it is "align to the vertical center".

It’s difficult for me to describe it.

Here is an image:

alt text

I would like align first and third column vertical on the middle. I want text in this 3 columns on the same "level:.

Func which create Table with this 3 columns is here:

    public Table ConvertToTabRp(IRp rp, string avatarNick)
    {
        var tempRp = new Rp { RpText = rp.RpText, Nick = rp.Nick, Time = rp.Time, Your = rp.Your };

        if (tempRp.Your)
            tempRp.Nick = avatarNick;

        string time = string.Format(CultureInfo.CurrentCulture, "{0}", DateTime.ParseExact(tempRp.Time, "yyyy-MM-dd HH:mm:ss", null)
            .ToString("dd-MM-yyyy HH:mm:ss").Replace("-", "."));

        var tab = new Table {Margin = new Thickness(0, 0, 0, 0)};

        var gridLenghtConvertor = new GridLengthConverter();

        //1. col
        tab.Columns.Add(new TableColumn { Name = "colNick", Width = (GridLength)gridLenghtConvertor.ConvertFromString("100") });
        //2.col
        tab.Columns.Add(new TableColumn { Name = "colMsg", Width = (GridLength)gridLenghtConvertor.ConvertFromString("Auto") });
        //3.col
        tab.Columns.Add(new TableColumn { Name = "colDt", Width = (GridLength)gridLenghtConvertor.ConvertFromString("150") });

        tab.RowGroups.Add(new TableRowGroup());
        tab.RowGroups[0].Rows.Add(new TableRow());

        var tabRow = tab.RowGroups[0].Rows[0];

        //1.col - NICK
        var pNick = new Paragraph(new LineBreak()) { TextAlignment = TextAlignment.Left };
        pNick.Inlines.Add(new Run(tempRp.Nick));

        if (!tempRp.Your)
        {
            pNick.Foreground = Brushes.DodgerBlue;
        }
        tabRow.Cells.Add(new TableCell(pNick));

        //2.col - MESSAGE
        tabRow.Cells.Add(new TableCell(ConvertToRpWithEmoticons(tempRp.RpText)) { TextAlignment = TextAlignment.Left});

        //3.col  - DATE TIME
        var pTime = new Paragraph(new LineBreak()) { TextAlignment = TextAlignment.Right };
        pTime.Inlines.Add(time);
        tabRow.Cells.Add(new TableCell(pTime));

        return tab;

    }

maybe solution can be:

        var pNick = new Paragraph(new LineBreak()) { TextAlignment = TextAlignment.Left , **VerticalTextAligment = Center** };

I don’t how vertical align in paragraph.

EDIT:

Maybe is problem in way how I add image to paragraph, here is it code:

            var image = new Image
            {
                Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)),
                Width = 20,
                Height = 20,
            };
            para.Inlines.Add(new Run(separatemsg.Text) { BaselineAlignment = BaselineAlignment.TextBottom });
            //insert smile
            para.Inlines.Add(new InlineUIContainer(image) {BaselineAlignment = BaselineAlignment.Bottom});

and this paragraph is add to 2. column.

Was it helpful?

Solution

Try use the BaselineAlignment-property.
Use a Run-Inline to put your text into the paragraphs and set the BaselineAlignment-property.

You can use this also for the image. Use for this the BaselineAlignment-property of the InlineUIContainer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top