Friday, August 19, 2011

StackPanel cannot stretch properly

Context: I created a TextBox element and a button; both inside a StackPanel. And I put the StackPanel inside a Grid. I gave the StackPanel HorizontalAlignement.Stretch. And I don't want to give width to my TextBox .

Problem: My StackPanel is not expanding to fill the available space!!! even though I gave it Stretch for HorizontalAlignment.

Solution: use DockPanel.

Reasoning: StackPanel is designed to shrink as much as its children accept.

2 comments:

Anonymous said...

I recommend UniformGrid instead of Dock.

Unknown said...

Thank you very much, I am going to try the UniformGrid. A very late reply (sorry).