Page 1 of 1

Issue with StoryboardCompletedTrigger not calling the InvokeCommandAction action

Posted: 10 May 2021, 15:14
by jinfox
Hello

I was trying to use StoryboardCompletedTrigger but however StoryboardCompletedTrigger.StoryboardChanged is correctly called and the event is attached but when the storyboard ends, it doesn't call the function.
<Grid Name="PART_mainGridLayout"  >
    <Grid.Resources>
        <Storyboard x:Key="LocationFanfare" >
            ...
        </Storyboard>
    </Grid.Resources>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource LocationFanfare}"  />
        </EventTrigger>
    </Grid.Triggers>

    <i:Interaction.Triggers>
        <!-- DOESN T WORK-->
        <ei:StoryboardCompletedTrigger Storyboard="{StaticResource LocationFanfare}">
            <i:InvokeCommandAction Command="{Binding NewLocationStoryboardCompletedCommand}"/>
        </ei:StoryboardCompletedTrigger>
    </i:Interaction.Triggers>
</Grid>
Is there a specific way to use this StoryboardCompletedTrigger and call a method?

Thank you

Re: Issue with StoryboardCompletedTrigger not calling the InvokeCommandAction action

Posted: 13 May 2021, 10:30
by sfernandez
Hi, I replicated your code in the following xamltoy and it seems to work:



Could you add another action (something obvious like changing the Width of an element or some text) to the StoryboardCompletedTrigger to see if that action works?
Is it possible that the binding to 'NewLocationStoryboardCompletedCommand' is not resolved? is that property part of Grid's DataContext

Re: Issue with StoryboardCompletedTrigger not calling the InvokeCommandAction action

Posted: 26 May 2021, 12:15
by jinfox
Hello!

Sorry for the delay in my reply.

I have tested your behavior and unfortunately it is the whole StoryboardCompletedTrigger that seems not to trigger at the end of the animation (even a simple ChangePropertyAction wouldn't change the color of a background for example).

If this makes a difference, the whole element is in a DataTemplate that is included in a ContentControl with a storyboard triggering on FrameworkElement.OnLoaded in the DataTemplate.

PS : I did a workaround using a DataTrigger listening on a property animated by the storyboard itself but that's a hack more than anything else.

Re: Issue with StoryboardCompletedTrigger not calling the InvokeCommandAction action

Posted: 27 May 2021, 11:22
by sfernandez
As I mentioned in our mail conversation this is related to this known issue with templates and StaticResources: #1822

The workaround, explained in that ticket, is to use Bindings to reference the storyboard so it gets resolved once the template is applied and it returns the correct object:
<ControlTemplate TargetType="Control">
  <Grid x:Name="root">
    <Grid.Resources>
      <ImageBrush x:Key="imgBrush" ImageSource="Test.png"/>
    </Grid.Resources>
    <Rectangle x:Name="rect" Fill="{Binding Resources[imgBrush], ElementName=root}"/>
  </Grid>
</ControlTemplate>