【问题标题】:MaxHeight on RowDefinition with Height=Auto ignoredRowDefinition 上的 MaxHeight,Height=Auto 被忽略
【发布时间】:2012-11-15 09:42:09
【问题描述】:

属性 MaxHeight 在 RowDefinitions 上似乎被 Height="Auto" 忽略:

考虑以下 XAML:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" MaxHeight="100"/>
  </Grid.RowDefinitions>
  <ListBox>
    <ListBox.Items>
      <ListBoxItem>a</ListBoxItem>
      <ListBoxItem>b</ListBoxItem>
      <ListBoxItem>c</ListBoxItem>
      <ListBoxItem>d</ListBoxItem>
      <ListBoxItem>e</ListBoxItem>
      <ListBoxItem>f</ListBoxItem>
      <ListBoxItem>g</ListBoxItem>
      <ListBoxItem>h</ListBoxItem>
      <ListBoxItem>i</ListBoxItem>
      <ListBoxItem>j</ListBoxItem>
    </ListBox.Items>
  </ListBox>
</Grid>

网格将大于 100 dip。

如何限制 RowDefinition 的高度?

【问题讨论】:

  • 您使用什么版本的 .NET?
  • .NET 4 在当前项目中。但如果 .NET 4.5 中有新内容,我也想听听。
  • 顺便说一句,刚刚发现这个小曲子似乎可以解决您的问题stackoverflow.com/questions/3294368/… 即使用“快捷方式”Height="*"

标签: c# .net wpf grid


【解决方案1】:

必须是别的东西。在干净的窗口中尝试过,列表框停在 100 像素处。 也许检查一下你的样式。

【讨论】:

  • 确实如此。这有点尴尬。
【解决方案2】:

将网格上的高度设置为自动并将 maxheight 保留在行定义上。

例如:

<Grid Height="Auto" Width="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="20" MinHeight="20" MaxHeight="20"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 2014-09-08
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多