use data trigger control the storyboard, but only trigger one time

淺唱寂寞╮ 提交于 2019-12-02 01:35:24

You can use System.Windows.Interaction.Interactivity with condition to launch storyboards.

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"

<Border x:Name="brd" MinWidth="20" Height="20">
<TextBlock Text="{Binding Text}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Border.Resources>
    <Storyboard x:Key="Story" Duration="1000"
            Storyboard.TargetName="brd"
            Storyboard.TargetProperty="Background">
        <ObjectAnimationUsingKeyFrames>
            <DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="#81bb8c" />
            <DiscreteObjectKeyFrame KeyTime="0:0:0.9" Value="{x:Null}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="Story2" Duration="1000"
            Storyboard.TargetName="brd"
            Storyboard.TargetProperty="Background">
        <ObjectAnimationUsingKeyFrames>
            <DiscreteObjectKeyFrame KeyTime="0:0:0.0" Value="#bb818c" />
            <DiscreteObjectKeyFrame KeyTime="0:0:0.9" Value="{x:Null}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</Border.Resources>
<i:Interaction.Triggers>
    <ei:DataTrigger Binding="{Binding LastClick}" Value="0"
            Comparison="GreaterThan">
        <ei:ControlStoryboardAction 
             Storyboard="{StaticResource Story}" ControlStoryboardOption="Play" />
    </ei:DataTrigger>
    <ei:DataTrigger Binding="{Binding LastClick}" Value="0"
            Comparison="LessThan">
        <ei:ControlStoryboardAction 
             Storyboard="{StaticResource Story2}" ControlStoryboardOption="Play" />
    </ei:DataTrigger>
</i:Interaction.Triggers></Border>
Shrivallabh

I had the same problem, then I gave Timeline.FillBehavior="Stop", which worked for me.

Check: Microsoft - Timeline Class Reference - Timeline.FillBehavior Property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!