结合“到”故事板中 [英] Binding to 'To' In Storyboard

查看:222
本文介绍了结合“到”故事板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会尽力使这个,我可以这么简单。

I'll try to make this as simple as I can.

我想这样做:

<Storyboard x:Name="MoveToLocation">
   <DoubleAnimation Duration="0:0:0.5" To="{Binding X}" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="grid" d:IsOptimized="True"/>
</Storyboard>

正如您可能已经注意到了绑定到属性不起作用。它似乎只接受静态值。

As you may have noticed the Binding on 'To' Property does not work. It seems to only accept static values.

怎样才能做到这一点的动画与MVVM?我不能只是把静态数据,因为它是不会改变。

How does one do this animation with MVVM? I cant just put in static data, cause it's going to change.

感谢。

推荐答案

DoubleAnimation是也不是一个 FrameworkElement的因此,绑定不工作,要么。看到我的回答你的previous <一个href=\"http://stackoverflow.com/questions/2984788/silverlight-binding-to-translatex\">question.

DoubleAnimation is also not a FrameworkElement hence binding doesn't work to that either. See my answer to your previous question.

为了在这里实现你的目标,你将需要采取你的的DataTemplate 的内容并把它变成一个用户控件。然后,这个新的控制可以公开一组的依赖属性,你需要绑定到,其中包括一个来的故事板值。

In order to achieve your goal here you will need to take the contents of your DataTemplate and turn it into a UserControl. This new control can then expose a set of dependency properties that you need to bind to, including one for To value of the storyboard.

这篇关于结合“到”故事板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆