tags:

views:

34

answers:

1

Hi

I have some xaml like this:

<UserControl.Resources>
    <Storyboard x:Name="sbLogo" x:Key="onLoadeducLogo" Completed="sbLogo_Completed">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image">
            <LinearDoubleKeyFrame x:Name="pauseKeyFrame" KeyTime="0:0:2" Value="0"/>
            <LinearDoubleKeyFrame x:Name="fadeInKeyFram" KeyTime="0:0:6" Value="1"/>
            <LinearDoubleKeyFrame x:Name="fadeOutKeyFrame" KeyTime="0:0:12" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</UserControl.Resources>

What I'd like to do is update the KeyTime values of the LinearDoubleKeyFrame elements from the UserControl code behind in C#.

I thought maybe I could do this by referencing those elements by their x:Name but I'm not having much success. I also thought maybe I could bind the values to a field in the code behind, but no success there either.

Has anyone got any clues to push me in the right direction.

Thanks Phil

+1  A: 

How have you tried to reference the LinearDoubleKeyFrame objects in code?

I think you need to do something like:

var storyboard = (Storyboard)FindResource("onLoadeducLogo");
var animation = (DoubleAnimationUsingKeyFrames)storyboard.Children[0];
var keyframe1 = animation.KeyFrames[0];

keyframe1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0,0,0,1)); // 1 second
Jay
@Jay brilliant, spot on. My mistake was trying to FindResource on "pauseKeyFrame" - of course now I see your answer I realise that the Storyboard is the resource. Thank you.
stupid-phil