Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Multiline TextBox for large content

Tags:

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?

like image 429
decasteljau Avatar asked Sep 11 '09 20:09

decasteljau


People also ask

How to make TextBox multiline in WPF?

Setting the TextWrapping attribute to Wrap will cause entered text to wrap to a new line when the edge of the TextBox control is reached, automatically expanding the TextBox control to include room for a new line, if necessary.

How do I wrap text in TextBlock WPF?

In WPF, the Label control does not support text wrapping. If you need a label that wraps contents across multiple lines, you can use a TextBlock control. Place a TextBlock control inside a Label and apply wrapping on TextBlock.

How do I create a line break in TextBlock WPF?

Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.

Which property allows multiple line input in TextBox?

A multiline text box allows you to display more than one line of text in the control. If the WordWrap property is set to true , text entered into the multiline text box is wrapped to the next line in the control.


1 Answers

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.

like image 163
codymanix Avatar answered Sep 21 '22 23:09

codymanix