如何以编程方式获取 WPF FrameworkElement 的当前视觉状态?
如何以编程方式获取 WPF FrameworkElement 的当前视觉状态?我所说的状态是指“正常”、“鼠标悬停”、“禁用”等状态。
编辑: 基本上,我正在使用 VisualStateManager.GoToState(e, "MouseOver", true);
更改按钮的视觉状态,并且我想知道完成后将其更改回什么状态。
How do I programmatically get the current Visual State of a WPF FrameworkElement? And by state I mean the states like "Normal", "MouseOver", "Disabled", etc.
EDIT:
Basically, I am changing the Visual state of a button with VisualStateManager.GoToState(e, "MouseOver", true);
, and I want to know what state to change it back to after I am done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你必须自己知道/记住按钮状态。 VSM只是通过
GoToState
方法显示按钮所处的状态。编辑:我刚刚找到一篇关于如何创建自定义 VSM 记住控件状态。
I think you have to know/remember the button state by yourself. VSM just displays the state in which the button is by
GoToState
method.Edit: I've just found an article how to create a custom VSM that remembers control states.
我觉得你在这里错过了 WPF 的要点,它是视图而不是模型。您不应该在视图中存储状态。将状态存储在模型中并使用视图来表示它。在此基础上,您不需要读取视图的状态,您已经知道了。
我知道目前这似乎是一项繁重的工作,但稍后它会给你带来回报。
I feel you've missed the point of WPF here, it's the View not the Model. You should not be storing state in the View. Store state in your Model(s) and use the View to represent it. On that basis you don't need to read the state of the View, you already know it.
I know this may seem like a lot of work at the moment but it'll pay you back in spades later.
我认为你应该使用 GoToElementState 方法而不是 GoToState 方法。
I think you should use GoToElementState method instead of GoToState method.