How do I calculate the correct height to automatically expand a textbox in Silverlight?

In my Silverlight application, I want a multi-line textbox to expand every time the user hits Enter.

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

I've tried the following, but the textbox gets 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 somehow automatically?

Thanks, Jacob

Edit: I suspect the problem is with the FontSize property (does it use a different size?)

0


source to share


2 answers


The textbox seems to work out of the box. Just make sure you set AcceptsReturn = "True" in the text box. Also make sure that you don't set the height of the text box to be calculated for you.



+3


source


TextBox

fires the event SizeChanged

and also sets the property ActualHeight

.



I don't think this was the case in Silverlight 2 where I had to use TextBlock

with the same font, set the padding to 4 and set the same text and disable ActualHeight

.

0


source







All Articles