Page 1 of 1

StopStoryboard in DataTrigger.EndActions

Posted: 21 Dec 2015, 16:28
by peterh
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>

Re: StopStoryboard in DataTrigger.EndActions

Posted: 24 Dec 2015, 12:15
by sfernandez
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.

Re: StopStoryboard in DataTrigger.EndActions

Posted: 29 Dec 2015, 12:24
by sfernandez
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>

Re: StopStoryboard in DataTrigger.EndActions

Posted: 07 Jan 2016, 14:42
by peterh
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.