How can a WPF StackPanel fill vertically from bottom to top? How can a WPF StackPanel fill vertically from bottom to top? wpf wpf

How can a WPF StackPanel fill vertically from bottom to top?


Like so:

<StackPanel VerticalAlignment="Bottom">    ...</StackPanel>

and to populate with buttons upward you must insert the buttons at position 0, instead of adding them.


Or you can rotate the StackPanel 180 degrees to get the buttons to stack from the bottom to the top and then rotating the buttons another 180 degrees to get them right-side-up again:

<StackPanel>    <!-- rotate all buttons inside this panel -->    <StackPanel.Resources>        <Style TargetType="Button">            <Setter Property="LayoutTransform">                <Setter.Value>                    <RotateTransform Angle="180"/>                </Setter.Value>            </Setter>        </Style>    </StackPanel.Resources>    <!-- rotate the stack panel -->    <StackPanel.LayoutTransform>       <RotateTransform Angle="180"/>    </StackPanel.LayoutTransform>    <!-- content -->    <Button>1</Button>    <Button>2</Button></StackPanel>


Another alternative is to use a DockPanel instead.

Just set the LastChildFill to false on the DockPanel.

Then set the attached Dock property to each button you are adding to Bottom before adding to the DockPanel.

example :

            var button = new Button();            DockPanel.SetDock(button, Dock.Bottom);