我正在尝试为 WPF Expander 控件创建一个 ControlTemplate,但我在尝试为 Expanded 和 Collasped 状态设置动画时遇到了障碍。
当应用程序最初启动时,我的 Expanded 状态动画触发一次,但之后不再触发。
我不确定这里发生了什么,但这是我的 ControlTemplate 目前的样子:
<ControlTemplate TargetType="Expander" x:Key="RightExpander">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Name="ContentColumn" Width="0" />
</Grid.ColumnDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ExpansionStates">
<VisualState x:Name="Expanded">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Content" Storyboard.TargetProperty="(RenderTransform).(TranslateTransform.X)" To="-50" From="0"
Duration="0:0:0.3" />
</Storyboard>
</VisualState>
<VisualState x:Name="Collasped">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Content"
Storyboard.TargetProperty="(RenderTransform).(TranslateTransform.X)"
To="50" From="0" Duration="0:0:0.3" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border Grid.Row="0" BorderThickness="1" Panel.ZIndex="1" >
<Grid>
<ToggleButton IsChecked="{Binding IsExpanded, Mode=TwoWay,
RelativeSource={RelativeSource
TemplatedParent}}"></ToggleButton>
<ContentPresenter ContentSource="Header"
RecognizesAccessKey="True"
IsHitTestVisible="False" />
</Grid>
</Border>
<Border Name="Content" Grid.Column="1" BorderThickness="0,1,1,1"
CornerRadius="0,5,5,0" Background="Pink" RenderTransformOrigin="0,0">
<Border.RenderTransform>
<TranslateTransform X="0" Y="0" />
</Border.RenderTransform>
<ContentPresenter Margin="4" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ContentColumn" Property="Width" Value="{Binding
ElementName=Content, Path=DesiredSize.Width}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
(我有一些虚假的 To 值只是为了测试。)我做错了什么?