首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableColumn /Paragraph中的文本对齐

TableColumn /Paragraph中的文本对齐
EN

Stack Overflow用户
提问于 2011-01-18 21:43:07
回答 1查看 3.1K关注 0票数 1

是否可以在中间的TableColumn中垂直对齐文本?

我将段落添加到表格的表格单元格中。我把这个表添加到richTexBox控件中。问题是中间列由图像(表情符号)组成,它是“与垂直中心对齐”。

我很难描述它。

以下是一幅图片:

我想在中间对齐第一列和第三栏。我希望这3列中的文本位于相同的“级别:。

使用这3列创建表的Func如下所示:

代码语言:javascript
复制
    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;

    }

也许解决办法可以是:

代码语言:javascript
复制
        var pNick = new Paragraph(new LineBreak()) { TextAlignment = TextAlignment.Left , **VerticalTextAligment = Center** };

我不知道段落中的垂直对齐。

编辑:

在我如何将图像添加到段落中时,可能存在问题,下面是代码:

代码语言:javascript
复制
            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});

这一段加到2.栏中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-18 21:50:52

尝试使用BaselineAlignment-property。

使用-Inline将文本放入段落并设置BaselineAlignment-属性。

您也可以将它用于图像。为此使用的是InlineUIContainer的基本别名-属性

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4729383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档