How to calculate the correct height for an auto-expanding textbox in Silverlight?

Posted by JacobE on Stack Overflow See other posts from Stack Overflow or by JacobE
Published on 2008-11-06T14:10:49Z Indexed on 2010/03/14 11:05 UTC
Read the original article Hit count: 296

Filed under:
|
|

In my Silverlight app I want a multi-line text box to expand every time the user hits Enter.

The difficult part is how to calculate the correct height based on the number of text lines.

I have tried the following but the textbox becomes too small:

box.Height = box.FontSize*lineCount + box.Padding.Top + box.Padding.Bottom + box.BorderThickness.Top + box.BorderThickness.Bottom;

What am I missing here? Or maybe it can be done automatically somehow?

Thanks, Jacob

Edit: I suspect the problem to be in the FontSize property (does it use another size unit?)

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about wpf