我有一个有三行的网格,前两行之间有一个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>
答案 0 :(得分:0)
你的行MinHeight值是罪魁祸首。
我测试了你的代码,当我调整窗口大小时,你正在描述的问题发生了,而不是当我拖动分割器时。
创建第二个网格并移出按钮将有所帮助。
<强> CODE:强>
<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>