0
我試圖摺疊擴展器時,當它摺疊其他grid
列不佔用空間。WPF - 摺疊時的擴展器不調整其他網格列
我在expander_collapsed
試過這個,網格佔用了整個空間,但是我不能訪問擴展器只能擴展它。
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
groupBoxMain.Visibility = Visibility.Visible;
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
MainGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
groupBoxMain.Visibility = Visibility.Hidden;
}
XAML代碼:
<Grid x:Name="MainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="177*"/>
<ColumnDefinition Width="133*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="680*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<GroupBox Name="groupBoxMain" BorderBrush="Black" Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="0" Margin="0,0,0,6">
<DataGrid Background="DarkGray" CanUserResizeColumns="True" CanUserSortColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding BackupVersionNumber}" Header="File Name" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
<DataGridTextColumn Binding="{Binding BackupDateTime}" Header="Total Time" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
<DataGridTextColumn Binding="{Binding SavedBy}" Header="Total Packet" MinWidth="100" FontFamily="Default Font" FontSize="16"/>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
<Expander ExpandDirection="Right" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" IsExpanded="True" Width="35" Grid.Row="0" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">
<Expander.Header>
<TextBlock Text="Select Manifest File" Width="Auto"
FontSize="11">
<TextBlock.LayoutTransform>
<TransformGroup>
<RotateTransform Angle="90"/>
</TransformGroup>
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<Grid Background="#FFE5E5E5" Width="0"/>
</Expander>
</Grid>
<Grid HorizontalAlignment="Stretch" Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Stretch" Height="Auto" Width="Auto" Margin="2,0,0,0.2">
<Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,10.4,0.267,0.2" Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}" />
</Grid>
</Grid>
我在我的主要grid
3列。一個是expander
,另外兩個是grid
。
我想要其他兩列佔用的空間,當expander
摺疊。
的根據XAML可能有助於回答這個問題,以及 – DonGru
增加了xaml代碼也是如此 – PSDebugger