[英]binding Storyboard in Usercontrol to Storyboard object in Viewmodel
在问这个问题之前,我已经搜索过了,但是我的情况有所不同。 我在UserControl中有一个命名的Storyboard,如下所示:
<Storyboard x:Key="Storyboard1" >
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="rectangle">
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="180"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="smartphone_png">
<SplineDoubleKeyFrame KeyTime="0:0:1.6" Value="205.5"/>
<SplineDoubleKeyFrame KeyTime="0:0:2.2" Value="205.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:4" Value="466.667"/>
<EasingDoubleKeyFrame KeyTime="0:0:5" Value="466.667"/>
<EasingDoubleKeyFrame KeyTime="0:0:6" Value="632.334"/>
<EasingDoubleKeyFrame KeyTime="0:0:7" Value="706.001"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="smartphone_png">
<EasingDoubleKeyFrame KeyTime="0:0:6" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:7" Value="53.333"/>
<EasingDoubleKeyFrame KeyTime="0:0:8" Value="196.166"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
在此用户控件的ViewModel中,我有类似以下内容绑定到Storyboard1 Storyboard:
Storyboard BoardControl = new Storyboard();
var resource =?? \\this line is what I need to bind to Storyboard1
BoardControl = resource as Storyboard;
BoardControl.Stop();
我努力了:
对象资源= Application.Current.TryFindResource(“ Storyboard1”);
这是错误的,因为它似乎初始化了一个新的Storyboard1对象,它与开始时的对象不同。
对我有任何想法,谢谢。
您无法从视图模型类控制或访问Storyboard
。
如果需要以编程方式控制Storyboard
,则应从视图的代码后面进行操作。 然后,您可以像下面这样访问Storyboard
资源:
Storyboard sb = this.Resources["Storyboard1"] as Storyboard;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.