How do I get stackpanel to resize to fit the controls it's stacking?
See the question and my original answer on StackOverflowDepending on your setting, you can achieve that simply using StackPanel's alignments. For example this XAML
<Window Width="350" Height="350" ...>
<Grid>
<StackPanel
Background="Green">
<Border
Width="100"
Height="100"
Background="Blue" />
<Border
Width="100"
Height="100"
Background="Red" />
</StackPanel>
</Grid>
</Window>
Will create this (the panel stretches to parent's size):
And this panel:
<Window Width="350" Height="350" ...>
<Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Green">
<Border
Width="100"
Height="100"
Background="Blue" />
<Border
Width="100"
Height="100"
Background="Red" />
</StackPanel>
</Grid>
</Window>
Will create this (sized to the two contained Borders):