【发布时间】:2015-08-13 08:50:27
【问题描述】:
我正在尝试将段落的格式化内容传输到 TextBlock,但格式消失了:
// Create a formatted paragraph
Paragraph para = new Paragraph();
para.FontSize = 25;
para.FontWeight = FontWeights.Bold;
para.Inlines.Add(new Run("Text of paragraph."));
// Create a span with the content of the paragraph (FontSize 25 and FontWeight Bold stay alive)
Span span = new Span(para.ContentStart, para.ContentEnd);
// Create a TextBlock with the span (FontSize 25 and FontWeight Bold get lost)
TextBlock textBlock = new TextBlock();
textBlock.Inlines.Add(span);
可以做些什么来保持格式?提前致谢。
更新
段落的格式在运行时是已知的,所以我不能手动一一应用属性值。
更新 2
问题的背景是我想测量格式化段落的长度,如果它们被拉伸到一行。
这可以通过 TextBlock 来完成。段落位于 TableCells 中,我想自动调整列宽。
【问题讨论】:
标签: c# wpf formatting textblock paragraph