中央の TableColumn のテキストを垂直方向に揃えることは可能ですか?
table の表のセルに段落を追加します。そして、このテーブルを richTexBox コントロールに追加します。問題は、中央の列が画像(絵文字)で構成されており、「垂直方向の中央に揃える」ことです。
それを説明するのは難しいです。
ここに画像があります:
1 列目と 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. 列に追加されます。