0

I'm dynamically filling two stackpanels with content at runtime and I want to set the height of these two stackpanels via a percentage. Here's what I've tried:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="3*" />
    <RowDefinition Height="2*" />
  </Grid.RowDefinitions>
  <ScrollViewer HorizontalAlignment="Stretch"
                Grid.Row="0">
    <StackPanel Name="gridEvents"
                Orientation="Vertical"
                HorizontalAlignment="Stretch">
      <Label Content="Foo" />
    </StackPanel>
  </ScrollViewer>
  <ScrollViewer HorizontalAlignment="Stretch"
                Grid.Row="1">
    <StackPanel Name="gridNewEvent"
                Orientation="Vertical"
                HorizontalAlignment="Stretch">
      <Label Content="Bar" />
    </StackPanel>
  </ScrollViewer>
</Grid>

If I change the RowDefinition height to a static value, it works. but not when I try a percentage. Any ideas?

Daniel
  • 10,864
  • 22
  • 84
  • 115
getintanked
  • 27
  • 1
  • 5
  • What percentage are you trying to use? Right now your RowDefinitions is defining Row1 at 3/5 and Row2 at 2/5, which seems like it would be correct. Also, what type of panel is your `Grid` hosted in? If it's inside a `StackPanel`, it will grow to whatever size its children need. – Rachel Nov 30 '12 at 20:53
  • Yes, I needed to first set my row definitions on the parents. Thank you! – getintanked Nov 30 '12 at 21:07

1 Answers1

1

Have you tried setting the height value of your grid? Otherwise it will expand to fill all available space and your rows will fill a percentage of the resulting grid. Also, it looks more like you're setting the value of your scrollviewers. Did you mean to say you were setting the height for those?

alan
  • 6,705
  • 9
  • 40
  • 70