C# – WPF Textbox binding and line breaks

bindingctextboxwpf

I have a textbox that i am binding to the viewmodel's string property. The string property is updated within the viewmodel and it displays the text within the textbox through binding.

The issue is that i want to insert the line break after a certain number of characters in the string property and i want that the line break is shown over the textbox control.

I tried appending \r\n inside the string property in viewmodel but the line break is not reflected over the textbox (i have Acceptsreturn property set to true inside the textbox)

Can anybody help.

Best Answer

The solution for me was to use HTML encoded line feeds ( ).

Line1
Line2

Looks like

Line1
Line2

From Naoki