我对 WPF 很陌生,所以如果这些天这是“老帽子”,请原谅......已经在网络/论坛上搜索过,但还没有找到我需要的答案:
我有一个包含 5 列的 WPF 网格 - 三列用于数据,两列用于 gridsplitters,这(感谢本网站上的信息!)似乎可以正常工作并调整大小。但是 - 我需要能够显示/隐藏中间列。我可以这样做,但是当我隐藏中间列时,左侧的 gridsplitter 仍然会影响“隐藏”列 - 我需要有效地在 2 和 3 列之间切换。这是我的(原型)代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Name="Col0" Width="*" />
<ColumnDefinition Name="Col1" Width="auto" />
<ColumnDefinition Name="Col2" Width="*" />
<ColumnDefinition Name="Col3" Width="auto" />
<ColumnDefinition Name="Col4" Width="auto" />
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" Height="100" HorizontalAlignment="Center" Margin="0" Name="GridSplitter1" VerticalAlignment="Stretch" Width="3" />
<GridSplitter Grid.Column="3" Height="100" HorizontalAlignment="Center" Margin="0" Name="GridSplitter2" VerticalAlignment="Stretch" Width="3" />
<Border BorderBrush="Silver" BorderThickness="1" Grid.Column="0" HorizontalAlignment="Stretch" Margin="0" Name="Border1" VerticalAlignment="Stretch" Background="#FFC84797" />
<Border BorderBrush="Silver" BorderThickness="1" Grid.Column="2" HorizontalAlignment="Stretch" Margin="0" Name="Border2" VerticalAlignment="Stretch" Background="Black" />
<Border BorderBrush="Silver" BorderThickness="1" Grid.Column="4" HorizontalAlignment="Stretch" Margin="0" Name="Border3" VerticalAlignment="Stretch" Background="#FFA60000">
<Button Content="hide" Height="33" Name="butHide" Width="85" />
</Border>
</Grid>
Private Sub butHide_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) 处理 butHide.Click If butHide.Content = "hide" Then butHide.Content = "显示" Col2.Width = 新 GridLength(0) Border2.Visibility = System.Windows.Visibility.Collapsed GridSplitter2.Visibility = System.Windows.Visibility.Collapsed 别的() butHide.Content = "隐藏" Col2.Width = 新 GridLength(1, GridUnitType.Star) Border2.Visibility = System.Windows.Visibility.Visible GridSplitter2.Visibility = System.Windows.Visibility.Visible 万一 结束子