银光 4 : How to trigger an Animation when TextBlock’s Text is changed during a DataBinding?

标签 silverlight data-binding silverlight-4.0

我有一个用户控制将哪个数据上下文设置为 View 模型。用户控件包含一些绑定(bind)到 View 模型属性的文本 block 和文本框。我想在 View 模型的属性值更改时做一个小动画,但我似乎无法在 Silverlight 中找到执行此操作的方法。

在 WPF 中,我们可以使用 NotifyOnTargetUpdated 和 Binding.TargetUpdated 等属性来捕获更改,但 Silverlight 似乎缺少这些属性。在我的例子中,动画不是基于属性的值,这意味着我不想在某些属性的值为例如 5 时启动动画。相反,每次属性值更改时动画都应该启动(以突出显示更改用户的内容)。

这是关于如何在 WPF 中执行此操作的答案:Animate WPF Text when binding updates, how?

但是我怎样才能对 Silverlight 4 做同样的事情呢?

最佳答案

您应该能够使用 Expression Blend 4 中包含的新触发器来完成此操作。例如,有一大堆新的行为/触发器等可以让您对 ViewModel 中的更改使用react。

来自 Expression Blend 功能页面:

New Behaviors Expression Blend includes the new TranslateZoomRotateBehavior multi-touch Behavior, and a PanningItems control that you can use to scroll between items by using touch. Expression Blend also has a new trigger that responds to a frame change or the pausing or completion of a SketchFlow animation, called the SketchFlowAnimationTrigger. Expression Blend has new sets of Behaviors for dragging items between list boxes, for modifying menu navigation, and for preserving screen states, such as SetDataStoreValueAction and DataStoreChangedTrigger.

An exciting enhancement has been made to the FluidMoveBehavior: if you apply it to different views of the same data item, when the item moves from one view to another (for example, from a list view to a details view), it fluidly animates the transition between the two views.

New Behaviors for use with applications that use the Model-View-ViewModel pattern include the following: CallMethodAction, InvokeCommandAction, and DataStateBehavior. You can use these Behaviors to invoke behavior on your ViewModels, or to respond to changes to their properties.

Conditional Behaviors and the data store You can now build conditional logic into your prototypes and production applications without the need to write code. In fact any action can be associated with a set of conditions that must be met in order to execute the action. The new data store feature enables application variables, such as the current user's role, for example, can be read from and written to so that, effectively, different parts of your application can communicate via this shared state.

New behavior components introduced as part of this feature include the conditions editor that appears in the Properties panel for every action, a SetDataStoreValueAction action that allows you to manipulate values in your data store, and a DataStoreChangedTrigger trigger that fires whenever a chosen property inside the data store is changed.

http://www.microsoft.com/expression/products/Blend_Features.aspx

干杯,亚历克斯

关于银光 4 : How to trigger an Animation when TextBlock’s Text is changed during a DataBinding?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3035190/

相关文章:

silverlight - 如何获取 datasourcechanged 事件?列表框

c# - 是否可以为 XAML 绑定(bind)到 View 模型启用智能感知?

datetime - DateTime在C#,Silverlight中从int转换为Month名称

windows-phone-7 - 使用资源本地化 Silverlight 应用程序

c# - 在 azure dev Fabric 上运行的 silverlight 中不会命中断点

c# - 向上增加矩形高度

vb.net - 如何在 Silverlight 3.0 中使用 SaveFileDialog 保存 BitmapImage/WriteableBitmap?

wpf - 在ViewModel中更改TextBlock的文本时运行动画

silverlight - 是否可以将 UserControl 的 DataContext 绑定(bind)到属性

silverlight - 从 ItemsControl.ItemTemplate 绑定(bind)到 View 模型属性