gpt4 book ai didi

wpf - 如何在 ControlTemplate 中获取动画资源?

转载 作者:行者123 更新时间:2023-12-04 20:51:54 25 4
gpt4 key购买 nike

....

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

最佳答案

这应该工作

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

关于wpf - 如何在 ControlTemplate 中获取动画资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5849581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com