StopStoryboard in DataTrigger.EndActions
I am writing a style containing a DataTrigger that will animate on certain states.
Right now, when leaving the state, the animation will not stop. I have tried including a StopStoryboard action in my DataTrigger.EndActions block, but no luck. Am I doing something wrong here?
Right now, when leaving the state, the animation will not stop. I have tried including a StopStoryboard action in my DataTrigger.EndActions block, but no luck. Am I doing something wrong here?
Code: Select all
<Style x:Key="MyStyle" TargetType="{x:Type common:MyComponent}">
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="Done">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Doing">
<Setter Property="Background">
<Setter.Value>
<RadialGradientBrush x:Name="RadialGradient" >
<GradientStop Color="White" Offset="0.0"/>
<GradientStop Color="{StaticResource Color.Active.Bright.Normal}" Offset="1.5"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="FlashingAnimation">
<Storyboard>
<DoubleAnimation x:Name="xAnimation"
Storyboard.TargetProperty="Background.RadiusX"
From="5" To="1" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever" />
<DoubleAnimation x:Name="yAnimation"
Storyboard.TargetProperty="Background.RadiusY"
From="5" To="1" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<StopStoryboard BeginStoryboardName="FlashingAnimation"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: StopStoryboard in DataTrigger.EndActions
Nothing wrong on your side, it seems a bug that affects also normal Triggers, not only DataTriggers. If a trigger sets a new Brush and animates it (on the Trigger.EnterActions), when the trigger stops being active, original Brush value is not restored, the animation stays playing.
Could you please add this bug to the bugtracker, thanks.
Could you please add this bug to the bugtracker, thanks.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: StopStoryboard in DataTrigger.EndActions
Hi,
While we solve this bug, you can use another Storyboard in the Trigger.ExitActions to transition to normal state brush:
While we solve this bug, you can use another Storyboard in the Trigger.ExitActions to transition to normal state brush:
Code: Select all
<Style x:Key="MyStyle" TargetType="{x:Type common:MyComponent}">
<Setter Property="Background">
<Setter.Value>
<RadialGradientBrush>
<GradientStop Color="Green" Offset="0.0"/>
<GradientStop Color="Green" Offset="1.5"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="Doing">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.GradientStops[0].Color"
To="White" Duration="0:0:0.2"/>
<ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color"
To="{StaticResource Color.Active.Bright.Normal}" Duration="0:0:0.2"/>
<DoubleAnimation Storyboard.TargetProperty="Background.RadiusX"
From="5" To="1" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetProperty="Background.RadiusY"
From="5" To="1" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.GradientStops[0].Color"
To="Green" Duration="0:0:0.5"/>
<ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color"
To="Green" Duration="0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
Re: StopStoryboard in DataTrigger.EndActions
Thanks for the tip, but I'm afraid my real use case is a bit too complex for that workaround to work. I'll have to do without the animation for the time being.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 63 guests