1

我有一个三行网格,前两行之间有一个 GridSplitter。第三行包含一个按钮。当 GridSplitter 被拖到窗口的中心或下部时,一切都会调整大小。当 GridSplitter 被拖到窗口顶部时,第二行无法正确调整大小,第三行被截断。

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:clr="clr-namespace:System;assembly=mscorlib"
    Width="300" MinHeight="300"  >
  <Grid ShowGridLines="True">
    <Grid.RowDefinitions>
      <RowDefinition MinHeight="130" />
      <RowDefinition MinHeight="50" />
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Rectangle Grid.Row="0" Fill="Aquamarine"/>
    <GridSplitter Grid.Row="0" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="5" />
    <ScrollViewer Grid.Row="1" >
      <Rectangle Height="500" Fill="Orange"/>
    </ScrollViewer>
    <Button Grid.Row="2" Content="Close" Width="70" HorizontalAlignment="Right" Margin="5" Click="Close_Click"/>
  </Grid>
</Window>
4

1 回答 1

0

您的行 MinHeight 值是罪魁祸首。

我测试了您的代码,您描述的问题发生在我调整窗口大小时,而不是当我拖动拆分器时。

创建第二个网格并将按钮移出会有所帮助。

代码:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:clr="clr-namespace:System;assembly=mscorlib"
    Width="300" MinHeight="300"  >
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid ShowGridLines="True">
            <Grid.RowDefinitions>
                <RowDefinition MinHeight="130" />
                <RowDefinition MinHeight="50" />
            </Grid.RowDefinitions>

            <Rectangle Grid.Row="0" Fill="Aquamarine"/>
            <GridSplitter Grid.Row="0" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="5" />
            <ScrollViewer Grid.Row="1" >
                <Rectangle Height="500" Fill="Orange"/>
            </ScrollViewer>

        </Grid>
        <Button Grid.Row="1" Content="Close" Width="70" HorizontalAlignment="Right" Margin="5"/>
    </Grid>
</Window>
于 2013-09-19T19:21:24.147 回答