简体   繁体   English

网格中的Stackpanel高度百分比

[英]Stackpanel height percentage within a grid

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. 如果我将RowDefinition高度更改为静态值,则可以使用。 but not when I try a percentage. 但是当我尝试一个百分比时却没有。 Any ideas? 有任何想法吗?

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. 同样,它看起来更像是在设置scrollviewer的值。 Did you mean to say you were setting the height for those? 您是说要设置这些身高吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM