我想流式传输一堆文本以显示长时间运行的任务(例如 Visual Studio 中的输出窗口)的状态/进度。
目前我有这样的XAML:
<ScrollViewer Canvas.Left="12" Canvas.Top="12" Height="129" Name="scrollViewer1" Width="678">
<TextBlock Name="text" TextWrapping="Wrap"></TextBlock>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
后面的代码:
private void Update(string content)
{
text.Text += content + "\n";
scrollViewer1.ScrollToBottom();
}
Run Code Online (Sandbox Code Playgroud)
一段时间后,它变得非常慢。
有没有推荐的方法来做这种事情?我是否使用了正确类型的控件?
谢谢!
至少,您需要使用 readonlyTextBox并使用该AppendText()方法来附加文本。
当然,如果您有足够的文本量,您仍然无法避免性能问题。在这种情况下,您可能需要研究虚拟化(数据和 UI)解决方案。
| 归档时间: |
|
| 查看次数: |
2581 次 |
| 最近记录: |