tags:

views:

70

answers:

1

I have a WPF windows where I want a section of at the top of the Window to be just the height of all the elements contained in it. The bottom section of the window should be be the adjustable height area. If the window made taller, then the bottom section should be the section that grows and not the top section.

Inside the bottom section of the window, I want two sections contained in it. The top section should be the adjustable height section and the bottom section should be just the height needed to display all the elements contained in it.

If you look at the xaml code below, you will see I have a total of three grids defined. The outer grid has two row definitions where the top row is set to Auto so that the height is just enough to contain all the elements contained in it. The second row should be adjustable to allow it to fill the rest of the size of the window.

Inside the second row of the outer grid is another grid that should allow for the first row to be flexible for height and the second row to be just tall enough for all the elements contained in it.

The problem I am having is that the entire window is not filled. The bottom grid is only part way down on the outer window. Why isn't the entire window filled by the bottom grid? How can I change the definition to allow for this?

<Window x:Class="WPFSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition />
        <RowDefinition Height="*" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid x:Name="TopGrid" VerticalAlignment="Top" Width="Auto" Height="Auto" Grid.Row="0">
        <Button Height="23" HorizontalAlignment="Left" Margin="60,0,0,4" Name="button1" VerticalAlignment="Bottom" Width="75">Button</Button>
    </Grid>
    <Grid x:Name="BottomGrid" Width="Auto" Height="Auto" VerticalAlignment="Bottom" Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Button Grid.Row="0" Height="23" Margin="60,0,61,4" Name="button2" VerticalAlignment="Bottom">Button</Button>
        <Button Grid.Row="1" Height="23" Margin="60,0,61,4" Name="button3" VerticalAlignment="Bottom">Button</Button>
    </Grid>
</Grid>

A: 

I figured this one out. I had multiple row definitions defined besides just the two I thought I had. Once I removed the extra ones, the formatting worked as expected.