WPF:激活触发器时,MVVM的绑定属性改变 [英] WPF: Activate Trigger when a MVVM bound property changes

查看:577
本文介绍了WPF:激活触发器时,MVVM的绑定属性改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知何故,我在圈子怎么回事。请原谅我,如果这个问题的答案是显而易见的。

somehow I am going in circles here. Please forgive me if the answer to this question is obvious.

我想对改变性质反应在视图模型中的视图。当属性(布尔)改变视图应该开始一个动画(BeginStoryBoard)。
其实在我的应用有这些属性的4每个模块在虚拟机自己的名称和两个期望每个动画(隐藏/显示)为相应的4容器视图元素。

I want to react to changed properties in the ViewModel in the View. When the properties (bool) change the View should start an animation (BeginStoryBoard). Actually in my application there are 4 of these properties each with its own name in the VM and two desired animations each (hide/show) for the respective 4 container view elements.

在设置这些触发器(试过DataTrigger /触发/的EventTrigger)直接在WPF给我的错误使用样式提示(从ContentConrol派生自定义类型SizerControl的全部)各自的容器元素。当在容器中的元素直接设置样式我:标签Style.Triggers'不存在XML命名空间存在......
但在全球ResourceDictionary中使用样式的时候我很茫然怎么绑定到4 containersto得到触发输入值。

When setting these Triggers (tried DataTrigger/Trigger/EventTrigger) directly in the respective container elements (all of them of custom type SizerControl derived from ContentConrol) wpf gave me errors suggesting using a style. When setting a style directly in the container elements I got: "The tag 'Style.Triggers' does not exist in XML namespace ..." But when using a style in a global ResourceDictionary I am at a loss how to bind to the 4 containersto get the "input" value for the trigger.

你有一个建议,如何从架构POV解决这个问题?也许我已经跌过头了错误的道路看到明显的解决方案。

Do you have a suggestion how to solve this from an architecture pov? Maybe I am already down too far the wrong path to see the obvious solution.

多谢,
Hinnerk

Thanks a bunch, Hinnerk

推荐答案

您可以用的 DataTrigger 和的故事板

MSDN有描述该过程的完整样本,以code,中的如何:触发的动画数据更改时

MSDN has a full sample describing the process, with code, documented in How to: Trigger an Animation When Data Changes.

这篇关于WPF:激活触发器时,MVVM的绑定属性改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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