可以在中间的 TableColumn 中垂直对齐文本吗?
我将段落添加到表格的表格单元格中。我将这张表添加到richTexBox 控件中。问题是中间列由图像(表情符号)组成,并且“与垂直中心对齐”。
我很难描述它。
这是一张图片:
我想在中间垂直对齐第一列和第三列。我希望这 3 列中的文本位于同一“级别:.
使用这 3 列创建表的函数在这里:
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;
}
也许解决方案可以是:
var pNick = new Paragraph(new LineBreak()) { TextAlignment = TextAlignment.Left , **VerticalTextAligment = Center** };
我不知道段落中的垂直对齐方式。
编辑:
也许是我如何将图像添加到段落的问题,这是代码:
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. 列。