如何在控件模板中获取动画资源?

4

....

 <ControlTemplate TargetType="{x:Type CheckBox}">
                <ControlTemplate.Resources>
                    <Storyboard x:Key="OnChecking">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
                                                       Storyboard.TargetName="slider"
                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                            <SplineDoubleKeyFrame x:Name="SplineValue"
                                                  KeyTime="00:00:00.3000000"
                                                  Value="25" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="OnUnchecking">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
                                                       Storyboard.TargetName="slider"
                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000"
                                                  Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                        <ThicknessAnimationUsingKeyFrames BeginTime="00:00:00"
                                                          Storyboard.TargetName="slider"
                                                          Storyboard.TargetProperty="(FrameworkElement.Margin)">
                            <SplineThicknessKeyFrame KeyTime="00:00:00.3000000"
                                                     Value="1,1,1,1" />
                        </ThicknessAnimationUsingKeyFrames>
                    </Storyboard>
                </ControlTemplate.Resources>

我可以通过下面的语句在代码后端获取"OnChecking"资源。

Storyboard stb1 = this.Template.Resources["OnChecking"] as Storyboard;

但是我如何在Storyboard中获取"SplineValue" SplineDoubleKeyFrame呢?
1个回答

1

这应该可以运行

 Storyboard stb1 = chk.Template.Resources["OnChecking"] as Storyboard;
 DoubleAnimationUsingKeyFrames animation =
                       (DoubleAnimationUsingKeyFrames)stb1.Children[0];
 var val = ((SplineDoubleKeyFrame)animation.KeyFrames[0]).Value;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接