从代码更新LinearDoubleKeyFrame KeyTime值

phi*_*gen 4 c# wpf

我有一些像这样的xaml:

<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>
Run Code Online (Sandbox Code Playgroud)

我想要做的是从C#后面的UserControl代码更新元素的KeyTimeLinearDoubleKeyFrame.

我想也许我可以通过引用这些元素来做到这一点,x:Name但我没有取得多大成功.我也想过,也许我可以将值绑定到后面的代码中的字段,但也没有成功.

有没有人有任何线索可以让我朝着正确的方向前进.

谢谢菲尔

Jay*_*Jay 5

你是如何尝试LinearDoubleKeyFrame在代码中引用对象的?

我想你需要做一些事情:

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
Run Code Online (Sandbox Code Playgroud)