如何在ControlTemplate中获取动画资源



。。。。

 <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;

但是,如何在情节提要中获取"SplineValue"SplineDoubleKeyFrame?

这应该能在中工作

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

最新更新