简体   繁体   English

如何从UserControl获取VisualStateGroup属性以在Silverlight 4 C#代码中的ViewModel中进行引用?

[英]How to get VisualStateGroup properties from a UserControl to reference in the ViewModel in Silverlight 4 C# code?

I'm trying to make visual states available in the ViewModel as some sort of enumeration (so that I don't have to use string literals or manually create and update static properties in order to be able to control states), and I accidentally found out that Silverlight actually generates internal VisualStateGroup properties in the gics classes which I could perhaps use. 我试图以某种枚举的形式在ViewModel中提供可视状态(这样我就不必使用字符串文字或手动创建和更新静态属性即可控制状态),我偶然发现了Silverlight实际上在gics类中生成了内部VisualStateGroup属性,我也许可以使用。

So my question is what would be the best way to expose these VisualStateGroups and the actual visual states in them as static getters? 所以我的问题是,将这些VisualStateGroups及其中的实际视觉状态显示为静态吸气剂的最佳方法是什么? Extending UserControl could work perhaps, but if possible I'd prefer do be able to do it on demand with an AttachedProperty, any ideas about the pros / cons or even workability of these approaches? 扩展UserControl也许可以工作,但是如果可能的话,我希望可以通过AttachedProperty来按需进行操作,关于这些方法的优缺点甚至可操作性有任何想法吗?

Thanks in advance! 提前致谢!

I support this in Jounce (http://jounce.codeplex.com/) and you can view the source. 我在Jounce(http://jounce.codeplex.com/)中支持此功能,您可以查看源代码。 Also take a look here where I describe how to iterate the visual state manager and hook into various events and iterate the states and transitions: 还可以在这里看看我在哪里描述如何迭代可视状态管理器并挂钩到各种事件以及迭代状态和过渡:

http://csharperimage.jeremylikness.com/2011/01/visual-state-manager-explained.html http://csharperimage.jeremylikness.com/2011/01/visual-state-manager-explained.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM