Pro*_*oll 5 wpf controls textview
我需要在WPF代码中显示大量的文本数据。首先,我尝试使用TextBox(当然渲染速度太慢)。现在我正在使用FlowDocument——而且它很棒——但最近我有另一个要求:文本不应该被连字符。据说它不是 ( document.IsHyphenationEnabled = false) 但我仍然没有看到我珍贵的水平滚动条。如果我放大比例文本是...连字符。
public string TextToShow
{
set
{
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(value);
FlowDocument document = new FlowDocument(paragraph);
document.IsHyphenationEnabled = false;
flowReader.Document = document;
flowReader.IsScrollViewEnabled = true;
flowReader.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
flowReader.IsPrintEnabled = true;
flowReader.IsPageViewEnabled = false;
flowReader.IsTwoPageViewEnabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我创建 FlowDocument 的方式 - 这是我的 WPF 控件的一部分:
<FlowDocumentReader Name="flowReader" Margin="2 2 2 2" Grid.Row="0" />
Run Code Online (Sandbox Code Playgroud)
没有犯罪 =))
我想知道如何驯服这只野兽 - 谷歌搜索没有任何帮助。或者你有一些替代方法来显示兆字节的文本,或者文本框有一些我只需要启用的虚拟化功能。无论如何,我会很高兴听到您的回复!
它确实是换行而不是连字符。通过将 FlowDocument.PageWidth 设置为合理的值可以克服这一问题,唯一的问题是如何确定该值。Omer 建议使用msdn.itags.org/visual-studio/36912/这个配方,但我不喜欢使用 TextBlock 作为文本测量工具。更好的方法:
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(value);
FormattedText text = new FormattedText(value, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(paragraph.FontFamily, paragraph.FontStyle, paragraph.FontWeight, paragraph.FontStretch), paragraph.FontSize, Brushes.Black );
FlowDocument document = new FlowDocument(paragraph);
document.PageWidth = text.Width*1.5;
document.IsHyphenationEnabled = false;
Run Code Online (Sandbox Code Playgroud)
奥马尔 - 感谢您的指导。
| 归档时间: |
|
| 查看次数: |
4083 次 |
| 最近记录: |