格式化RichtextBox WPF中的文本

格式化RichtextBox WPF中的文本,wpf,text,richtextbox,formatting,Wpf,Text,Richtextbox,Formatting,我尝试在richTextBox中格式化文本,类似于skype聊天 1.column-"Nick" 2.column-"Text of Messange" 3.column-"DateTime" 我想要alling 1。列的最大值为左和3。列最大右侧 最好的方法是什么?我怎么做?我正在使用WPF。我的解决方案: 简单的解决方案是创建表对象并添加到richtextbox的块中,如下所示: var tab = new Table();

我尝试在richTextBox中格式化文本,类似于skype聊天

1.column-"Nick"         2.column-"Text of Messange"                3.column-"DateTime" 
我想要alling 1。列的最大值为左和3。列最大右侧


最好的方法是什么?我怎么做?我正在使用WPF。

我的解决方案:

简单的解决方案是创建表对象并添加到richtextbox的块中,如下所示:

        var tab = new Table();

        var gridLenghtConvertor = new GridLengthConverter();

        tab.Columns.Add(new TableColumn() { Name = "colNick", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });
        tab.Columns.Add(new TableColumn { Name = "colMsg", Width = (GridLength)gridLenghtConvertor.ConvertFromString("5*") });
        tab.Columns.Add(new TableColumn() { Name = "colDt", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });

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

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


        tabRow.Cells.Add(new TableCell(new Paragraph(new Run(rpMsg.Nick))) { TextAlignment = TextAlignment.Left });

        tabRow.Cells.Add(new TableCell(ConvertToRpWithEmoticons(rpMsg.RpText)));

        tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Cas"))) { TextAlignment = TextAlignment.Right });

        RtbConversation.Document.Blocks.Add(tab);

为什么要使用一个RichTextBox(而不是三个(Rich)TextBlock)?我认为这不是一个好的解决方案,例如,如果你的RichTextBox已满,你必须滚动3个richtetbox,而且你在RichTextBox中的行高也有问题。。。。