9

I want to create a UI element that behaves approximately like the native WP SMS App's input text box.

Basically it should

  • start as a single line text box
  • when my text reaches the end of the first line, it should expand one line to encompass it
  • this needs to go to a Max Height of 5 line (where a line = the text box's Height value)
  • once my text requires more than 5 lines, the text box should stop expanding and a vertical scroll bar should appear

Any suggestions on how I can do this? I'd rather not use events to see how much text I've entered and expand/compress the text box based on that, or create a new UI element from scratch.

If it helps, I've got access to Telerik's RAD Controls for Windows Phone (RadTextBox).

1 Answer 1

21

Have you attempted making use of the FrameworkElement.MaxHeight property? The markup would be similar to:

<TextBox TextWrapping="Wrap" AcceptsReturn="True" MaxHeight="200" />

The given value for max height is simply an example and may not meet your specific needs.

Note: As mentioned in the comments below, be certain to remove any value specified for Height. The declaration will constrain the element to that height at all times.

4
  • Doesn't modify the actual height of the element - no matter how many characters I enter, the text box is still displayed as a one line text box.
    – drl
    Commented Oct 7, 2013 at 14:45
  • 2
    @drl Be certain you don't have a value specified for Height. That will constrain the element to that height at all times. Test with a MaxHeight value of 200 as that is approximately five lines.
    – lsuarez
    Commented Oct 7, 2013 at 16:03
  • It worked perfectly when I took out the explicit height! It even works to shrink the text box when I'm deleting text. Seriously thank you!
    – drl
    Commented Oct 7, 2013 at 18:08
  • @lthibodeaux: i am not able to get vertical scroll bars
    – Kuldeep
    Commented Dec 3, 2014 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.