peterh
Topic Author
Posts: 39
Joined: 13 Mar 2015, 13:50

StopStoryboard in DataTrigger.EndActions

21 Dec 2015, 16:28

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?
<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>
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: StopStoryboard in DataTrigger.EndActions

24 Dec 2015, 12:15

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.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: StopStoryboard in DataTrigger.EndActions

29 Dec 2015, 12:24

Hi,

While we solve this bug, you can use another Storyboard in the Trigger.ExitActions to transition to normal state brush:
<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>
 
peterh
Topic Author
Posts: 39
Joined: 13 Mar 2015, 13:50

Re: StopStoryboard in DataTrigger.EndActions

07 Jan 2016, 14:42

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