Search code examples
wpfxamlwindows-phone-8

Windows Phone 8 - Filling a stackpanel with a button


Suppose I make the following screen in my app (this is just an example, actual layout is a bit more complex but works on the same principle):

  • Vertical StackPanel
    • TextBlock (fits/wraps its content size AKA Auto size)
    • Button 1 (Auto)
    • Button 2

I would like to make Button 2 stretch so that it occupies the remainder of the screen's height, so there cannot be a specific Height property - but VerticalAlignment="Stretch" and VerticalAlignment="Bottom" don't do the trick, and in fact don't do anything at all. Is there any way to handle that?


Solution

  • in this case i generally prefer to use a grid, you can use something like this:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
    </Grid>