我在 Border 控件中有一个 Expander 控件。当 Expander 折叠时,边框保持相同的高度。我如何使边框也改变它的高度?说明问题的代码:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="2" />
</Style>
<Style TargetType="StackPanel" x:Key="StackPanel1">
<Setter Property="Orientation" Value="Vertical"/>
<Setter Property="MaxHeight" Value="100" />
</Style>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" x:Key="panelBackgroundBrush">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFE3EFFF" Offset="0" />
<GradientStop Color="#FFAFD2FF" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style TargetType="{x:Type GridSplitter}">
<Setter Property="FrameworkElement.Height" Value="3"/>
<Setter Property="UIElement.SnapsToDevicePixels" Value="True" />
<Setter Property="UIElement.Focusable" Value="False" />
<Setter Property="FrameworkElement.Cursor" Value="SizeNS"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Border BorderThickness="0" BorderBrush="{StaticResource panelBackgroundBrush}">
<Canvas Width="19" Height="3">
<Canvas.Resources>
<Style TargetType="Rectangle">
<Setter Property="Width" Value="2" />
<Setter Property="Height" Value="2" />
<Setter Property="Canvas.Top" Value="0" />
</Style>
</Canvas.Resources>
<Rectangle Fill="{StaticResource panelBackgroundBrush}" Canvas.Left="1" />
<Rectangle Fill="{StaticResource panelBackgroundBrush}" Canvas.Left="5" />
<Rectangle Fill="{StaticResource panelBackgroundBrush}" Canvas.Left="9" />
<Rectangle Fill="{StaticResource panelBackgroundBrush}" Canvas.Left="13" />
<Rectangle Fill="{StaticResource panelBackgroundBrush}" Canvas.Left="17" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Canvas.Left="0" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Canvas.Left="4" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Canvas.Left="8" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Canvas.Left="12" />
<Rectangle Fill="{TemplateBinding TextElement.Foreground}" Canvas.Left="16" />
</Canvas>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Border>
<Expander>
<Border>
<StackPanel Style="{StaticResource ResourceKey=StackPanel1}" >
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
</StackPanel>
</Border>
</Expander>
</Border>
<Border Grid.Row="1">
<Expander>
<Border>
<StackPanel Style="{StaticResource ResourceKey=StackPanel1}" >
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
</StackPanel>
</Border>
</Expander>
</Border>
<GridSplitter Grid.Row="1" />
<Border Grid.Row="2">
<Expander>
<Border>
<StackPanel Style="{StaticResource ResourceKey=StackPanel1}" >
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
<TextBlock Text="aaaa"/>
</StackPanel>
</Border>
</Expander>
</Border>
<GridSplitter Grid.Row="2" />
</Grid>