2010-09-06 133 views
2

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

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" /> 

没有犯罪=))

我想知道如何驯服这只野兽 - 谷歌搜索没有任何帮助。或者你有其他的方式来显示兆字节的文本,或者文本框有一些我需要启用的虚拟化功能。无论如何,我很乐意听到你的回应!

+2

你的问题不是连字符。它环绕着。看看这里:http://msdn.itags.org/visual-studio/36912/,他们建议设置大于视图窗口的段落宽度。 – OmerGertel 2010-09-06 17:34:19

+0

谢谢奥默尔 - 链接和建议似乎相当明智。将尽快尝试:) – ProfyTroll 2010-09-06 21:00:29

+0

在此处查看答案:https://stackoverflow.com/questions/807347/how-do-i-handle-edit-large-amount-of-text-in-wpf/46546877#46546877 – juFo 2017-10-03 14:21:51

回答

1

它真的包装不是连字符。我们可以通过将FlowDocument.PageWidth设置为合理的值来解决这个问题,唯一的问题是如何确定这个值。 奥默尔建议这个配方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; 

奥梅尔 - 谢谢你的方向。

相关问题