Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a new line in wpf textbox

I created a small GUI with WPF, containing a Textbox. I want the user to have the ability to start a new line . How do I let the user start a new line in the WPF textbox (with \n or \r)? I want the user to be able to start a new line by pressing "enter".

like image 371
MoShe Avatar asked Oct 23 '11 09:10

MoShe


People also ask

How do I create a new line in TextBlock WPF?

Adding Line Breaks 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. If you have configured the text to be justified, the final line before the line break will not be expanded to fill the available width.

How do you insert a line break in XAML?

XAML attributes of type String may contain any special characters, as long as those are referenced as hex-codes. For example, a simple line break ( \n ) would be represented as 
 , for \r\n you'd use 
 and so on.

What is TextBlock WPF?

The TextBlock control provides flexible text support for UI scenarios that do not require more than one paragraph of text. It supports a number of properties that enable precise control of presentation, such as FontFamily, FontSize, FontWeight, TextEffects, and TextWrapping.

How do I make a TextBox readonly in WPF?

To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.


1 Answers

have you try set on your textbox following property:

TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" (or auto) AcceptsReturn="True" 
like image 55
Kamil Lach Avatar answered Sep 21 '22 23:09

Kamil Lach