Silverlight 和数据绑定属性动画(边距)
我有 Border 元素,其 Margin 属性绑定到某个类的 StartDate (DateTime) 属性。如果属性发生变化,保证金也会发生变化(在转换器的帮助下)。
我想尽可能顺利地做出改变。例如,在 UI 方面,数据类中的 1 小时等于屏幕上的 15 像素,当我更改 StartDate +/- 1 小时时,我可以看到元素边距向右/向左跳跃 +/- 15 像素...那么我怎样才能动画这个?
先感谢您!
顺便说一句 - 这是我的第一个问题:)
I have Border element with Margin property bound to StartDate (DateTime) property of some class. If property changed margin is changed also (with a help of converter).
I'd like to make changes as smoothly as possible. for example, on UI side one hour in data class equals to 15 pixels on screen and when i change StartDate +/- one hour i can see that element margin jumping by +/- 15 pixels right/left... so how can i animate this?
Thank you in advance!
BTW - this is my first question here :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您无法通过动画本身操纵边距。边距实际上是一个厚度对象,对于简单的属性动画师来说,对象几乎不可能自己弄清楚。
然而,就像现在的任何事情一样,有很多方法可以覆盖它:
移动对象的位置而不是边距:
在 Silverlight 中动画边距变化
创建一个与中的 ThicknessAnimation 类类似的新类WPF 并在代码中调用它: http ://blogs.msdn.com/blemmon/archive/2009/03/18/animating-margins-in-silverlight.aspx
...或者我的首选方式:找到其他动画。您可以操纵不同的对象来移动其他对象。您可以非常轻松地对不可见/透明对象的宽度和高度进行动画处理。如果该项目是堆栈面板中的第一个项目,则该项目之后的所有项目都将随着其大小值的更改而移动。这可能会变得很挑剔,但确实很容易做到。
祝你好运!
Unforunately you can't natively manipulate a margin through an animation. A margin is really a Thickness object and objects are almost impossible for the simple property animator to figure out on their own.
However, like anything now-a-days, there are many ways to override this:
Move the position of the object instead of the margin:
Animate Margin Change in Silverlight
Create a new class similar to the ThicknessAnimation class in WPF and call it in code: http://blogs.msdn.com/blemmon/archive/2009/03/18/animating-margins-in-silverlight.aspx
...or my preferred way: Find something else to animate. You can manipulate a different object which moves your other objects over. You can animate width and height of an invisible/clear object very easily. If that item is the first thing in a stack panel, all items after it will be moved as it's size values are changed. This can become finicky, but it is really easy to do.
Good luck!