根据属性值更改 VisualState
如何根据 WP7 上的属性值更改 VisualState?
我尝试使用 MVVM 模式,当我的模型加载时,我希望我的视图进入特定的 VisualState。
在 Silverlight 中,我们有属性更改的触发器,但在 WP7 中没有!
PS:我不想使用框架我想了解它在WP7中是如何完成的。
How to change a VisualState based on a property value on WP7?
Im trying to use MVVM pattern and when my model is loading I want my view to go to especific VisualState.
In Silverlight we have triggers for property changes but in WP7 not!
PS: I dont want to use frameworks I want to understand how it is done in WP7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用以下附加行为:
在视图模型中,公开当前视觉状态的属性,然后在要处理视觉状态的视觉元素上使用以下内容来绑定视觉状态,例如
I use the following attached behavior:
In your view model, expose a property for the current visual state, and then on the visual element that you want to handle the visual state for you use the following to bind the visual state, for example
最初,DataStateBehavior 行为看起来是完美匹配,这篇文章甚至专门讨论了使用用WP7就可以了
但是,本文引用的 Codeplex 项目不再具有该行为,并且该行为不在 Expression Blend 中(至少对于 WP7 项目而言)。
我倾向于在 ViewModel 上公开一个属性,并以编程方式侦听视图中的更改并相应地更改视觉状态:
在视图的构造函数中:
然后创建一个相应更改状态的事件处理程序:
Damian
Initially the DataStateBehavior behavior looks to be a perfect match, and this article even specifically talks about using it with WP7.
However the Codeplex project the article references no longer has the behavior, and the behavior is not in Expression Blend (at least for WP7 projects).
I'd be inclined to expose a property on the ViewModel and programatically listen for changes in the View and change the Visual State accordingly:
In your View's constructor:
Then create an event handler that changes the state accordingly:
Damian