开发者

Start animation that begins with current value (handoff).

开发者 https://www.devze.com 2022-12-10 01:16 出处:网络
I have a WPF Datatemplate that contains a some DataTriggers that start animating the color of a visual. How can I start the animation beginning with the actual value the color property currently has?

I have a WPF Datatemplate that contains a some DataTriggers that start animating the color of a visual. How can I start the animation beginning with the actual value the color property currently has?

Since there might be another animation curren开发者_运维知识库tly active I can not start a new one but when I remove the animation using DataTriggers ExitAction and RemoveStoryboard the position property is set back to its default value.

Instead I would like handoff one to the other.

Is this a limitation of WPF that simply can not be done?

<DataTrigger Binding="{Binding Path=State}" Value="Active">
    <DataTrigger.EnterActions>
        <BeginStoryboard x:Name="activeStoryboard" HandoffBehavior="SnapshotAndReplace">
            <Storyboard>
                <ColorAnimation To="Green" FillBehavior="HoldEnd" Duration="00:00:0.25" 
                                Storyboard.TargetName="stateBrush" 
                                Storyboard.TargetProperty="Color" />
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
        <RemoveStoryboard BeginStoryboardName="activeStoryboard" />
    </DataTrigger.ExitActions>
</DataTrigger>
<DataTrigger Binding="{Binding Path=State}" Value="Error">
    <DataTrigger.EnterActions>
        <BeginStoryboard x:Name="errorStoryboard" HandoffBehavior="SnapshotAndReplace">
            <Storyboard>
                <ColorAnimation To="Red" FillBehavior="HoldEnd" Duration="00:00:0.25" 
                                Storyboard.TargetName="stateBrush" 
                                Storyboard.TargetProperty="Color" />
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
    <DataTrigger.ExitActions>
        <RemoveStoryboard BeginStoryboardName="errorStoryboard" />
    </DataTrigger.ExitActions>
</DataTrigger>


It should just work if you start the second animation, even if FillBehavior is set to Stop!

Check the following section on msdn: FillBehavior="Stop" and HandoffBehavior with Multiple Animations

0

精彩评论

暂无评论...
验证码 换一张
取 消