嘿伙计我有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>
答案 0 :(得分:11)
将窗口的SizeToContent
设置为"WidthAndHeight"
,不要将其设置为Width
或Height
或designWidth或designHeight。
答案 1 :(得分:3)
将事件处理程序附加到展开器的折叠事件,并从窗口宽度中减去((Expander)sender).ActualWidth -20