是否可以在中间的TableColumn中垂直对齐文本?
我将段落添加到表格的表格单元格中。我把这个表添加到richTexBox控件中。问题是中间列由图像(表情符号)组成,它是“与垂直中心对齐”。
我很难描述它。
以下是一幅图片:

我想在中间对齐第一列和第三栏。我希望这3列中的文本位于相同的“级别:。
使用这3列创建表的Func如下所示:
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.栏中。
发布于 2011-01-18 21:50:52
尝试使用BaselineAlignment-property。
使用跑-Inline将文本放入段落并设置BaselineAlignment-属性。
您也可以将它用于图像。为此使用的是InlineUIContainer的基本别名-属性
https://stackoverflow.com/questions/4729383
复制相似问题