嘿伙计们,我有 3 个列扩展器,当您将它们全部打开并调整窗口大小时,它们会正确拉伸以适应窗口。当您关闭扩展器时,我希望它在打开时将窗口缩小该扩展器的宽度。它目前将扩展器关闭到 20 像素,但打开的扩展器会更大(它会拉伸以填充空白空间)。
代码:
<UserControls:ExpanderWindow x:Class="Lainezor.Windows.ExpanderWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xt="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
xmlns:pg="clr-namespace:Microsoft.Windows.Controls.PropertyGrid;assembly=WPFToolkit.Extended"
xmlns:MyUserControls="clr-namespace:Lainezor.UserControls.ExpanderControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SizeToContent="WidthAndHeight" Background="AliceBlue"
ResizeMode="CanResize" WindowStartupLocation="Manual" Loaded="Window_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="20" />
<Setter Property="MinWidth" Value="20" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsExpanded, ElementName=Expander1}" Value="True">
<Setter Property="Width" Value="20*" />
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
<ColumnDefinition Width="2"/>
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="20" />
<Setter Property="MinWidth" Value="20" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsExpanded, ElementName=Expander2}" Value="True">
<Setter Property="Width" Value="20*" />
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
<ColumnDefinition Width="2"/>
<ColumnDefinition>
<ColumnDefinition.Style>
<Style TargetType="ColumnDefinition">
<Setter Property="Width" Value="20" />
<Setter Property="MinWidth" Value="20" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsExpanded, ElementName=Expander3}" Value="True">
<Setter Property="Width" Value="20*" />
</DataTrigger>
</Style.Triggers>
</Style>
</ColumnDefinition.Style>
</ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Expander Name="Expander1" Grid.Column="0" IsExpanded="True" IsEnabled="True" ExpandDirection="Right">
<Expander.Header>
<TextBlock Text="{Binding Source={StaticResource ResourceWrapper}, Path=MyStrings.Expander1Label}" RenderTransformOrigin="0,0" >
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<MyUserControls:UserControl1 x:Name="UserControl1" SizeChanged="UserControl1_SizeChanged"/>
</Expander>
<GridSplitter x:Name="gridSplitter" Grid.Column="1" Width="2" Background="#CBE5FE" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" />
<Expander Grid.Column="2" Grid.RowSpan="2" Name="Expander2" ExpandDirection="Right" Grid.IsSharedSizeScope="True">
<Expander.Header >
<TextBlock Text="{Binding Source={StaticResource ResourceWrapper}, Path=MyStrings.Expander2Label}">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90" />
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<MyUserControls:UserControl2 x:Name="UserControl2" HorizontalAlignment="Stretch"/>
</Grid>
</Expander>
<GridSplitter x:Name="gridSplitterTwo" Grid.Column="3" Width="2" Background="#CBE5FE" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" />
<Expander Grid.Column="4" Grid.RowSpan="2" Name="Expander3" ExpandDirection="Right">
<Expander.Header >
<TextBlock Text="Lainezor">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90" />
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<MyUserControls:UserControl3 x:Name="UserControl3" HorizontalAlignment="Stretch" />
</Grid>
</Expander>
</Grid>