开发者

How to get the animation resource inside a ControlTemplate?

....

 <ControlTemplate TargetType="{x:Type CheckBox}">
                <ControlTemplate.Resources>
                    <Storyboard x:Key="OnChecking">
                        <DoubleAnim开发者_如何学CationUsingKeyFrames 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>

....

I can get the Resource "OnChecking" in the code behind using the below statement.

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

But How can i get the "SplineValue" SplineDoubleKeyFrame inside the Storyboard?


This should work

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜