tags:

views:

24

answers:

2

Right now I have a problem with stack panels inside dock panels. Often the stack panel is taller than necessary for the contents, so the contents are stretched.

Is there something I can place in or around the stack panel to mean "don't cause children to consume all avaialble space".

A: 

Well, what do you want your StackPanel to do? If you want it to only consume the visible space, use a grid. If you want to scroll the contents of your StackPanel, I believe you can put it in a ScrollViewer.

Dave Markle
I'm fine with the stack panel consuming all the space itself. What I don't like is the button inside the stack panel also consuming all the space.
Jonathan Allen
I think Schneider might know what's going on.
Dave Markle
+2  A: 

AFAIK the contents of the StackPanel do not "stretch" to fill it, anymore than any other control. i.e. the stretch to fill will be controlled by the HorizontalAlignment and VerticalAlignment of the child elements.

The default is usually Stretch. Try setting it to Left etc.

Schneider
I don't think the stretching is caused by the stack panel itself, but by whatever the stack panel is in.
Jonathan Allen
Whatever the stackpanel is in, should not affect the stackpanels children. I tried a sample with a stackpanel in a dock panel as you state and it works fine - I can choose to stretch or not stretch the children of the stackpanel. Can you post a code sample?
Schneider
Thanks. Your answer didn't make sense before, but now that I know more about WPF I see that you were correct.
Jonathan Allen