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

标签 wpf controls textview

我需要在 中显示大量的文本数据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" />

没有犯罪 =))

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

最佳答案

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

Omer - 感谢您的指导。

关于wpf - 在 WPF 中显示大文本的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3653182/

相关文章:

c# - 更改 ViewModel 对象不会反射(reflect)对 View 的更改

android - MotionLayout中的TextView在大小动画上闪烁

ios - 如何在保持光标快速移动的同时隐藏键盘

android - 屏幕旋转后如何恢复textview滚动位置?

WPF 验证手动将错误添加到 Validation.Errors 集合中

.net - 是否可以在 Silverlight/WPF 中选择性地为包装 TextBlock 着色

WPF进行 View /编辑控件的好方法吗?

winforms - Winforms下的右键菜单

asp.net - 如何将组名应用于 asp.net 中的 HTML 单选按钮?

c# - WPF Tab 键导航