Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
690
Limiting text entered to two lines
posted

I have been given this requirement to limit the text entered in a textbox/XamTextEditor to two lines.  Unfortunately, I am not allowed to use a monospace/fixed widht font like 'Courier New' - I would have simply used the MaxLength property of the control.  Instead I have to use a variable font, so the maxlength is unknown.  MFC used to allow for this feature out of the box by simply not specifying a maxlength and not allowing for scrolling, but I don't see how to do this in WPF with an Infragistic XamTextEditor.

In this thread, Curtis Taylor showed how we can get the linecount as the user types text.  I wrote a small prototype using this idea and when the linecount=3, I truncated the last character and set the textbox.text to the be the new truncated value.  

This way I always have two lines and this kind of worked - unfortunately, when I set the textbox.text to the new string, the focus caret is placed at the beggining of the textbox.  This obviously doesn't work since the user now continues typing from the beggining of the first line instead of not being able to type more characters at the end of the second line.

 Curtis (or anyone else), do you have any idea on how I could handle this crazy requirement?  I can post the XAML and code-behind if needed.