2011-03-25 59 views
2

我想知道是否有任何方法通过更改XAML代码来解决此问题?调整WPF中的另一个网格行大小

请看看这个样品图片:

enter image description here

我想要做的是,当用户拖动GridSeparater 1号,我要调整电网的THR第三排。

这是因为在这个应用程序中,第一和第三行是可变大小,但第二个是固定大小。

这可能吗?

回答

4

这是可能的ResizeBehaviour="PreviousAndNext"Link to MSDN)。这使您可以指定哪些行相对于GridSplitter应该受到影响。

<Grid Width="300" Height="200" Background="Yellow" ShowGridLines="True"> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="20"/> 
    <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

        <GridSplitter Grid.Row="1" 
         ResizeDirection="Rows" 
         ResizeBehavior="PreviousAndNext" 
         HorizontalAlignment="Stretch" 
         VerticalAlignment="Top" 
         Background="Black" 
         ShowsPreview="True" 
         Height="5" 
         /> 



</Grid> 
+0

酷 - 不知道ResizeBehaviour。学到了什么,thx! – 2011-03-25 19:05:25

+0

不错的一个!我发现ShowsPreview =“True”非常重要。如果您没有设置该属性,则GridSplitter行为将允许您完全折叠顶部行,并且无法恢复。 +1 – Stewbob 2011-03-25 19:12:06

1

您可以尝试在中央行上将MinHeight和MaxHeight设置为相同的值,这会在调整顶部大小时强制重新计算底部部分。事情是这样的:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="50" MaxHeight="50" MinHeight="50"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions>   
    ... other content 
    <GridSplitter Height="3" Grid.Row="1" HorizontalAlignment="Stretch"/> 
    <GridSplitter Height="3" Grid.Row="3" HorizontalAlignment="Stretch"/> 
    </Grid>