我试图发送一个段落TextBlock的格式化的内容,但格式消失:如何将已格式化的段落插入到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中,我想自动调整列宽。
我无法直接应用样式,请参阅上面的我的更新。 – Pollitzer
看到我上面的更新 - 你可以从段落中的样式,仍然直接在代码中应用它们。 – nepdev
段落的格式可以是任何东西,不一定总是指整个范围,所以,不幸的是,我不能这样做。请参阅我的更新2. – Pollitzer