views:

106

answers:

0

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 propery currently has? Since there might be another animation currently acitve 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>