Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ColorAnimation, StoryBoard and DataTrigger: Starts but doesn't stop

$
0
0
Hi

In a control template I have a rectangle whose style has a DataTrigger that listens to some boolean view model prop, which is most of the time set to "false".
When it turns to "true" a StoryBoard starts with a ColorAnimation that oszillates from one FIll-color to another
and back. This works fine and is all XAML.
However when the view model property turns back to "false" the storyboard and its color animation do not stop
but keeps on oscillating.

I'll show you my code:

<!-- StoryBoard in DataTrigger to change Fillcolor when "IsRotating" turns to true  --><Style x:Key="IsRotatingOuterFillStyle"
           TargetType="Shape"><Setter Property="Shape.Fill"
                Value="{StaticResource ResourceKey=ThumbsInvertedBrush}" /><Style.Triggers><DataTrigger Binding="{Binding Path=IsRotating}"
                         Value="True"><DataTrigger.EnterActions><BeginStoryboard><Storyboard><ColorAnimation Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                            To="{StaticResource ResourceKey=ThumbsColor}"
                                            Duration="0:0:1"
                                            RepeatBehavior="Forever"
                                            AutoReverse="True" /></Storyboard></BeginStoryboard></DataTrigger.EnterActions></DataTrigger></Style.Triggers></Style>
<!-- custom control template that consume sthe style with the DataTrigger and the SotryBoard and that doesn't stop when "IsRotating" turns to false back again --><thumbs:RotationPointThumb.Template><ControlTemplate><Grid><Rectangle Height="{Binding ElementName=ZoomContextRotationPoint,Path=ZoomedSize2}"
                               VerticalAlignment="Center"Style="{StaticResource ResourceKey=IsRotatingOuterFillStyle}"
                               Margin="{Binding ElementName=ZoomContextRotationPoint,Path=ZoomedThickness1}" />
...

Of course the question is:
How to I convince the StoryBoard to stop when the DataTrigger turns to false again?
If possible without code-behind, pure XAML?

I already debugged the code and can rule out that the DataTrigger doesn't fire properly.
If I don't use a StoryBoard but just change the fill with a setter it works out fine.
It's the storyboard/coloranimation that ignores the reset.
Is there some special code that I need to STOP the storyboard?

Thanks,
Chris

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>