WPF - setting HorizontalAlignment= Stretch to Textbox in StackPanel

Malcolm picture Malcolm · Jan 2, 2009 · Viewed 16.6k times · Source

Why doesn't a textbox stretch to fill space in a stackpanel? Is this by design? In a grid, the textbox stretches as expected.

Answer

Kent Boogaart picture Kent Boogaart · Jan 2, 2009

Yes, it's by design. The StackPanel will allocate the space the TextBox asks for. If you haven't set a width on the TextBox, it will require only enough width to fit its text.