locked
binding not working for Storyboard DoubleAnimationUsingKeyFrames RepeatBehavior

    Question

  • Is it possible to bind to the DoubleAnimationUsingKeyFrames' RepeatBehavior dependency property?

    In the below example, the StoryBoard is started when the Image's Loaded event fires (using the Behaviors SDK).

    I have an int property in the bound object named "SecondsRemaining". Think of it as a countdown timer. When the countdown timer reaches 0, I want to stop the StoryBoard from continuing to loop (but I want it to finish the current loop). So I made a converter for int to RepeatBehavior. Below is the important part of the converter:

    return (value is int && ((int)value > 0)) ? RepeatBehavior.Forever : new RepeatBehavior(0);

    The converter never gets called. Below is the xaml. See the DoubleAnimationUsingKeyFrames for the relevant part. I'm not sure the Storyboard or DoubleAnimationUsingKeyFrames are even seeing the same data context that the template sees.

        <DataTemplate x:Name="SearchResultDataTemplate2" >
            <Button>
                <Grid Width="250" Height="250" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
    
                    <Image x:Name="FrontImage" Grid.Row="0" Grid.RowSpan="2" Source="{Binding StationImage}" Stretch="Uniform" VerticalAlignment="Top" >
                        <Interactivity:Interaction.Behaviors>
                            <Core:EventTriggerBehavior EventName="Loaded">
                                <Media:ControlStoryboardAction >
                                    <Media:ControlStoryboardAction.Storyboard>
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames AutoReverse="False" RepeatBehavior="{Binding SecondsRemaining, Converter={StaticResource IntToRepeatBehaviorConverter}}"
                                                Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" 
                                                Storyboard.TargetName="FrontImage">
                                                <!-- bunch of EasingDoubleKeyFrame(s) removed from code sample -->
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </Media:ControlStoryboardAction.Storyboard>
                                </Media:ControlStoryboardAction>
                            </Core:EventTriggerBehavior>
                        </Interactivity:Interaction.Behaviors>
                        <Image.RenderTransform>
                            <CompositeTransform TranslateX="0" />
                        </Image.RenderTransform>
                    </Image>
    				
    		<!-- bunch of other controls removed from code sample -->
    
                </Grid>
            </Button>
        </DataTemplate>
    

    Thank you for any suggestions you have.

    Tuesday, October 21, 2014 1:46 AM

All replies

  • Hi Arthur,

    Can you send me a repro project? I cannot troubleshooting the issue with the available code. Use your OneDrive and share a link here.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, October 22, 2014 6:25 AM
    Moderator
  • Thanks for the offer Herro, but I decided to look at this problem a different way by creating a UserControl. With the UserControl I don't mind adding a little more code-behind. So it was pretty easy then to wait for the Image's ImageOpened event (instead of Loaded) and then start a storyboard with a RepeatBehavior based on a TimeSpan equal to my seconds remaining countdown.
    Wednesday, October 22, 2014 11:50 PM
  • Hi Arthur,

    Have you solved this problem? If you need help, please post more information about this case.

    If you have solved this problem, can you share a solution or work around here? It will help other community member with similar question.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, October 28, 2014 6:20 AM
    Moderator