1

嗨,我有一种样式,当它设置为可见时,它会为边框及其内容设置动画。EnterAction 工作得很好,但当内容控件设置为隐藏或折叠时 ExitAction 不起作用。

风格 :

<Style x:Key="BorderTransition" TargetType="{x:Type ContentControl}">
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="BorderBrush" Value="{StaticResource AccentBrush}"></Setter>
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="ContentControl">
            <Border x:Name="container" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0">
                <ContentPresenter 
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    RecognizesAccessKey="True"/>
            </Border>                   
            <ControlTemplate.Triggers>
                <Trigger Property="IsVisible" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation 
                                    Storyboard.TargetName="container" 
                                    Storyboard.TargetProperty="Opacity" 
                                    From="0.0" 
                                    To="1.0" 
                                    Duration="00:00:02" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName="container" Storyboard.TargetProperty="Opacity" Duration="0:0:10">
                                    <LinearDoubleKeyFrame Value="1" KeyTime="0:0:0" />
                                    <LinearDoubleKeyFrame Value="1" KeyTime="0:0:9" />
                                    <LinearDoubleKeyFrame Value="0" KeyTime="0:0:10" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

问候,

4

0 回答 0