我正在将一个超过 25MB 的巨大文档加载到 FlowDocument 中。一切都很好,但是在初始化过程中需要更多的 cpu 或很长时间才能将整个数据加载到 FlowDocument 中。取而代之的是,有一种方法可以根据在 FlowDocument 控件底部单击的下一页动态加载页面。
流文档的示例代码。
<ScrollViewer HorizontalAlignment="Stretch">
<GroupBox>
<GroupBox.Header>
<TextBlock Text="Standard Output"></TextBlock>
</GroupBox.Header>
<FlowDocument Name="flowDocument" ColumnWidth="999999" Background="Transparent" IsColumnWidthFlexible="True" >
<Paragraph Name="para" Background="Transparent" TextAlignment="Justify" KeepTogether="True">
</Paragraph>
</FlowDocument>
</GroupBox>
</ScrollViewer>
我在文件后面的代码中分配数据。
在代码隐藏文件中填充流文档的代码。
para.Inlines.Add(ReadDocument());
public void ReadDocument()
{
textToDisplay = File.ReadAllText(@"C:\sampleLog.txt");
}