gpt4 book ai didi

c# - 在扩展器关闭时缩小窗口大小

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:32 24 4
gpt4 key购买 nike

大家好,我有 3 个列扩展器,当您将它们全部打开并调整窗口大小时,它们会适当拉伸(stretch)以适合窗口。当您关闭扩展器时,我希望它在打开时将窗口缩小该扩展器的宽度。它目前将扩展器关闭回 20 像素,但打开的扩展器会更大(它会拉伸(stretch)以填充空白空间)。

代码:

<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>

最佳答案

将窗口的 SizeToContent 设置为 "WidthAndHeight" 并且不要设置它的 WidthHeight 或designWidth 或 designHeight。

关于c# - 在扩展器关闭时缩小窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com