在WPF中显示大文本的最佳方式?

问题描述 投票:3回答:1

我需要在WPF代码中显示大量的文本数据。首先我尝试使用TextBox(当然渲染速度太慢)。现在我正在使用FlowDocument - 它真棒 - 但最近我有另一个请求:文本不应该连字符。据说它不是(document.IsHyphenationEnabled = false)但我仍然没有看到我珍贵的水平滚动条。如果我放大缩放文本是...连字符。

alt text

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;
    }
}

这就是我创建FlowDocument的方法 - 这是我的WPF控件的一部分:

<FlowDocumentReader Name="flowReader" Margin="2 2 2 2" Grid.Row="0" />

没有犯罪=))

我想知道如何驯服这种野兽 - 谷歌没有任何帮助。或者您有一些替代方法来显示兆字节的文本,或者文本框具有一些我需要启用的虚拟化功能。无论如何,我很乐意听到你的回复!

wpf controls textview
1个回答
1
投票

这真的包装不是连字符。可以通过将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;

欧麦尔 - 感谢方向。

© www.soinside.com 2019 - 2024. All rights reserved.