locked
TextBox.Height: Filled vs Empty

    Question

  • One of my most common problems when designing the XAML for my apps is making the height of a TextBox stay the same when it is used and blank. I leave the Height property set to the default value of Auto, and set the FontSize. But the Height of the TextBox is different when the Text property is blank and when it is set to a non-whitespace value. This change also occurs during runtime when the user enters (or deletes) text from the TextBox. This makes for a very ugly UI, because the layout is constantly changing. Shouldn't the size of a TextBox stay the same? The FontSize is not being changed, and neither is any other property (other than the Text property). The only workarounds I have found involve explicitly setting the Height or MinHeight properties, but this should not be necessary, and means recalculating the height anytime I use a different FontSize. How can I make the Height stay the same regardless of whether there is anything in the Text Property? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Friday, December 19, 2014 5:21 PM

Answers

  • No. The TextBox doesn't have enough data to choose the minimum size until it has text in it, so it cannot do so automatically (font and fontsize are not sufficient to know how big the text will be in all languages). Better default prediction is being investigated for future versions.

     

    Saturday, December 20, 2014 4:21 AM
    Owner

All replies

  • Even though that posting was marked as an answer, as stated by the last poster the "answer" of setting the Text to " " is not appropriate, because it provides incorrect data. Are there any other ways to automatically size the TextBox without putting text in it? I even tried setting the PlaceholderText property to " ", which made the TextBox closer in size to when it has text, but still not the same. Any ideas?

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Saturday, December 20, 2014 4:05 AM
  • No. The TextBox doesn't have enough data to choose the minimum size until it has text in it, so it cannot do so automatically (font and fontsize are not sufficient to know how big the text will be in all languages). Better default prediction is being investigated for future versions.

     

    Saturday, December 20, 2014 4:21 AM
    Owner