简体   繁体   English

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

[英]Best way to show huge text in WPF?

I need to show a really huge amount of text data in WPF code. 我需要在WPF代码中显示大量的文本数据。 First i tried to use TextBox (and of course it was too slow in rendering). 首先,我尝试使用TextBox (当然,渲染速度太慢)。 Now i'm using FlowDocument --and its awesome--but recently i have had another request: text shouldnt be hyphenated. 现在我正在使用FlowDocument - 它很棒 - 但最近我有另一个请求:文本不应该连字符。 Supposedly it is not ( document.IsHyphenationEnabled = false ) but i still don't see my precious horizontal scroll bar. 据说它不是( document.IsHyphenationEnabled = false )但我仍然没有看到我珍贵的水平滚动条。 if i magnify scale text is ... hyphenated. 如果我放大缩放文本是...连字符。

替代文字

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

That's how i create FlowDocument - and here comes part of my WPF control: 这就是我创建FlowDocument的方法 - 这是我的WPF控件的一部分:

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

Nothing criminal =)) 没有犯罪=))

I'd like to know how to tame this beast - googled nothing helpful. 我想知道如何驯服这种野兽 - 谷歌没有任何帮助。 Or you have some alternative way to show megabytes of text, or textbox have some virtualization features which i need just to enable. 或者您有一些替代方法来显示兆字节的文本,或者文本框具有一些我需要启用的虚拟化功能。 Anyway i'll be happy to hear your response! 无论如何,我很乐意听到你的回复!

It's really wrapping not hyphenation. 这真的包装不是连字符。 And one can overcome this by setting FlowDocument.PageWidth to reasonable value, the only question was how to determine this value. 可以通过将FlowDocument.PageWidth设置为合理的值来克服这一点,唯一的问题是如何确定此值。 Omer suggested this recipe msdn.itags.org/visual-studio/36912/ but i dont like using TextBlock as an measuring instrument for text. Omer建议使用这个配方msdn.itags.org/visual-studio/36912/,但我不喜欢使用TextBlock作为文本的测量工具。 Much better way: 好多了:

            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;

Omer - thanks for the direction. 欧麦尔 - 感谢方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM