我遇到了问题GridSplitter
简单示例代码:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid x:Name="TopGrid" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red"/>
<GridSplitter ResizeDirection="Rows" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="2" Background="Black" />
<Grid x:Name="BottomGrid" Grid.Row="2" HorizontalAlignment="Stretch" Background="Aquamarine" VerticalAlignment="Stretch"/>
</Grid>
这将创建两个由 . 垂直分隔的 Grid GridSplitter
。
我想要实现的是,GridSplitter
自动对齐网格的内容。例如,如果我在底部网格中有一个可折叠元素,我希望顶部网格在折叠元素时变得更大。如果我扩大它,顶部Grid
应该变小。
我该怎么做呢?稍后我将有 4Grids
和 3GridSplitter
的...所以该解决方案也应该适用于多个GridSplitter
。
[编辑]:
我的xml:
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100">
<RowDefinition.MinHeight>
<MultiBinding Converter="{StaticResource ResourceKey=MultiValueConverter}">
<Binding ElementName="dgStapelliste" Path="ActualHeight"></Binding>
</MultiBinding>
</RowDefinition.MinHeight>
</RowDefinition>
<RowDefinition Height="1"></RowDefinition>
<RowDefinition Height="*"></RowDefinition >
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" x:Name="Test">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<WPF:DataGrid GridHeaderContent="{Binding StapelListe.HeaderText}" SelectedItem="{Binding StapelListe.SelectedItem}" Grid.Row="0" Grid.Column="0" x:Name="dgStapelliste" HorizontalAlignment="Stretch" ItemsSource="{Binding StapelListe, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
<WPF:DataGrid GridHeaderContent="{Binding EinzelListe.HeaderText}" Grid.Row="0" Grid.Column="1" x:Name="dgEinzelliste" HorizontalAlignment="Stretch" ItemsSource="{Binding EinzelListe, Mode=OneWay}"/>
<GridSplitter Grid.Column="0" Width="1" VerticalAlignment="Stretch" Background="Black" />
</Grid>
<Grid Grid.Row="2" Grid.Column="0" Grid.RowSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<WPF:DataGrid GridHeaderContent="{Binding Anforderungsliste.HeaderText}" Grid.Column="0" x:Name="dgAnforderungsliste" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Anforderungsliste, Mode=OneWay}"/>
<GridSplitter Grid.Column="0" Width="1" VerticalAlignment="Stretch" Background="Black" />
</Grid>
<GridSplitter Grid.Column="0" Grid.Row="1" Height="1" ResizeDirection="Rows" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" x:Name="testSplitter" />
</Grid>