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".
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.
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.
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.
To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.
have you try set on your textbox following property:
TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" (or auto) AcceptsReturn="True"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With