Joseph Le Brech
Joseph Le Brech

Reputation: 6653

Grid Layouts in silverlight

I have two grid rows which will vary in terms of the content of them.

I want the top row to have it's content centred vertically within than row.

And the bottom row aligned to the bottom vertically.

<Grid>     
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="60*" />
    </Grid.RowDefinitions>  
    <Grid Grid.Row="0" VerticalAlignment="Top">
        <Grid VerticalAlignment="Center">
            <StackPanel>
                ...
            </StackPanel>                
        </Grid>
    </Grid>

    <StackPanel Grid.Row="1" VerticalAlignment="Bottom" d:LayoutOverrides="GridBox">
         ...           
    </StackPanel>
</Grid>

This is what it should look like.

  +-----------------------------+               +--------------------------------+
  |                             |               |                                |
  |                             |               |                                |
  |                             |               |                                |
  | Content Centered            |               |                                |
  |                             |               |                                |
  |                             |               | Content Centered               |
  |                             |               |                                |
  +-----------------------------+     or        |                                |
  |                             |               |                                |
  |                             |               |                                |
  |                             |               |                                |
  |                             |               +--------------------------------+
  |                             |               |                                |
  | Content at the bottom       |               | Content at the bottom          |
  +-----------------------------+               +--------------------------------+

The content of the rows can vary, I've used rowdefinitions at some point but it didn't work because I don't know a fixed height for either row.

Upvotes: 1

Views: 1158

Answers (1)

Claus J&#248;rgensen
Claus J&#248;rgensen

Reputation: 26344

So, as I said, Grid.Row="1" have no effect unless you use define a series of RowDefinition elements. Anyway, the issue you describe is easy enough,

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid VerticalAlignment="Center">
            <!-- stuff here is center aligned -->
        </Grid>
    </Grid>
    <Grid Grid.Row="1">
        <Grid VerticalAlignment="Bottom">
            <!-- stuff here is bottom aligned -->
        </Grid>
    </Grid>
</Grid>

Upvotes: 1

Related Questions