为什么这个VisualStateManager只触发一次动画?

时间:2012-08-10 16:46:05

标签: wpf c#-4.0 controltemplate visualstatemanager visualstategroup

我正在尝试为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>

(我有一些虚假的价值只是为了测试。)我做错了什么?

1 个答案:

答案 0 :(得分:3)

我的猜测是Collapsed(Collasped)的拼写错误

由于拼写错误,VSM可能无法找到故事板