适用于大内容的 WPF 多行文本框

发布于 2024-08-04 08:24:32 字数 403 浏览 1 评论 0原文

在 WPF 应用程序中,我想构建一个“在文件中查找”输出窗格,在其中可以流式传输大量文本,而无需像 TextBox 那样在每一行重新分配内存。

WPF TextBox 有一个存储连续字符串的 Text 属性。每次,我想添加内容,我都需要执行 textBox.Text += "New Text",这很糟糕。

理想情况下,该控制应该是虚拟的,并且只需要最少的资源(仅用于可见线)。

我考虑过将标准 ListBoxVirtualizingStackPanel 一起使用,但它不允许跨行文本选择。

(在添加的每个新行中,我希望更新控件)

有什么建议吗?

In a WPF application, I want to build a "Find in Files" output pane, in which I can stream large quantity of text, without re-allocating memory at each line, like the TextBox would do.

The WPF TextBox has a single Text property which stores a contiguous string. Each time, I want to add content, I need to do textBox.Text += "New Text", which is bad.

Ideally, that control would be virtual and require a minimum of resources, just for the visible lines.

I thought about using a standard ListBox with a VirtualizingStackPanel, but it does not allow Text Selection across lines.

(At each new line added, I want the control to update)

Any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

流殇 2024-08-11 08:24:32

如果您不希望应用程序中的搜索结果超过一万个,那么到目前为止,TextBlock 控件或只读多行 TextBox 就足够了。

TextBox 类有一个 AppendText() 方法,该方法对您来说应该足够快。

如果您需要文本突出显示/格式化,那么也许您想使用 RichTextBox。

If you do not expect much more than ten-thousands of search results in your application, a TextBlock control or readonly multiline TextBox will suffice by far.

The TextBox class has an AppendText() method which should be fast enough for you.

If you need text highlighting / formatting then maybe you want to use RichTextBox.

红墙和绿瓦 2024-08-11 08:24:32

如果您的内容非常大,那么不幸的是所有 WPF 文本框和类似控件都非常慢。请参阅此问题。您可以使用 AvalonEdit 作为替代品。

If you have really large content, then unfortunately all the WPF textbox and similar controls are very slow. See this question. You could use AvalonEdit as a replacement.

娇纵 2024-08-11 08:24:32

您是否考虑过或尝试过 RichTextBox 控件?

Have you considered or tried the RichTextBox control?

十六岁半 2024-08-11 08:24:32

一个 StringBuilder,只需将文本附加到字符串构建器,而不是执行

textBox.Text += moreText;

do

myStringBuilder.Append(moreText);
textBox.Text = myStringBuilder.ToString();

这应该处理 Schlemiel the Painter 的 算法。

当然,字符串生成器应该是您的类的成员,以便它在您的对象的生命周期中存在。

A StringBuilder, just append the text to the String builder and instead of doing

textBox.Text += moreText;

do

myStringBuilder.Append(moreText);
textBox.Text = myStringBuilder.ToString();

This should take care of the Schlemiel the Painter's algorithm.

Of course, the string builder should have to be a member of your class so it exists through your object's life span.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文