Multiline issue WPF TextBox

c#, multiline, textbox, wpf

Solution

Andrey Gordeev's answer is right (+1 for him) but does not provide a direct solution for your problem. If you check the `textBox1.Text` string with the debugger you would see the referred `\r\n` characters. On the other hand, if you intend to affect them directly (via `.Replace`, for example), you wouldn't get anything.

Thus, the practical answer to your question is: rely on `Environment.NewLine`. Sample code:

label1.Content = textBox1.Text.Replace(Environment.NewLine, "").Length;

Problem

I creating multiline `TextBox` with this Link its work better but if I want to set `TextBox` text counter `label1.Content = textBox1.Text.Length;` with above line work fine but problem is that when I press enter in the `TextBox` counter it will increase 2 characters in `TextBox` counter. How can I do this task please help me. Any help appreciated!

Original source

Related problems