【问题标题】:GridSplitter inside Expander expanding beyond a heightExpander 内的 GridSplitter 扩展超出高度
【发布时间】:2012-09-22 14:03:50
【问题描述】:

我有一个扩展器,其中包含一个网格,其中我有一个网格拆分器。

文档大纲和用户界面是这样的

这是代码。

<Grid x:Name="TopGrid" ShowGridLines="True" >
 <Grid.RowDefinitions>
  <RowDefinition Height="Auto" MaxHeight="150"/>
  <RowDefinition Height="200" />
 </Grid.RowDefinitions>
 <Expander x:Name="CompanyDescriptionExpander" Grid.ColumnSpan="2" 
           VerticalAlignment="Top" IsExpanded="True" Background="Black" >
  <Expander.Header>
   <Grid Width="{Binding ElementName=CompanyDescriptionExpander, 
                         Path=ActualWidth}" Background="Aquamarine">
    <TextBlock Grid.Column="0" Text="Expander Header" Foreground="Black" />
   </Grid>
  </Expander.Header>
   <Expander.Content>
    <Grid x:Name="DescriptionGrid" MaxHeight="130" ShowGridLines="True">
     <Grid.RowDefinitions>
      <RowDefinition Height="*" MinHeight="25" MaxHeight="25"/>
      <RowDefinition Height="Auto" MinHeight="25" MaxHeight="120"/>
      <RowDefinition Height="4" MinHeight="10" MaxHeight="10"/>
     </Grid.RowDefinitions>
     <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="Auto" />
     </Grid.ColumnDefinitions>
     <TextBox Grid.Column="0" Background="Orange" Grid.Row="0" Grid.RowSpan="2"
              MinHeight="40" MaxHeight="120" x:Name="DescriptionText"
              Text="TextBlock Content" HorizontalAlignment="Stretch" 
              VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" 
              VerticalContentAlignment="Top" 
              HorizontalScrollBarVisibility="Hidden" 
              VerticalScrollBarVisibility="Auto" />
     <Button x:Name="SaveIconButton" Grid.Column="1" Grid.Row="0" Width="20" 
             Height="20" VerticalAlignment="Top" />
     <Button x:Name="CancelIconButton" Grid.Column="1" Grid.Row="1" Width="20" 
             Height="20" VerticalAlignment="Top" />
     <GridSplitter ResizeBehavior="PreviousAndCurrent" ResizeDirection="Rows" 
                   Grid.Row="2" Grid.ColumnSpan="2" 
                   Height="10" MaxHeight="10" HorizontalAlignment="Stretch" 
                   VerticalAlignment="Top" Background="Red" />
    </Grid>
   </Expander.Content>
 </Expander>
 <Button Grid.Row="1" Grid.Column="0" Margin="0,5,0,0" Height="20" 
         VerticalAlignment="Top" Background="Green" />
</Grid>

当我们使用网格分割器时,它会扩展

但即使在文本框达到其最大高度并且 gridsplitter 落后于按钮(绿色)之后它也会继续。

我的问题场景可以复制到项目中复制我的代码

我希望它在文本框达到最大高度时停止。

怎么做?

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    在您的 DescriptionGrid 中,将第二行 MaxHeight 从 120 更改为 95。

    该网格中三行的组合最大高度超过了网格本身的最大高度。

    【讨论】:

      猜你喜欢
      • 2016-11-18
      • 1970-01-01
      • 2012-03-08
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多