更改“菜单”状态的最佳方法是WPF 中的用户控件
我有一个 UserControl,我想要有 3 种可能的状态:(
-Main menu
-Config #1
-Config #2
所有三个都是带有各种按钮、文本框等的 UserControl,父 UserControl 的状态根据当前状态将子控件设置为可见/不可见。
)菜单状态有按钮可以转到两个配置状态之一(这两个状态都有一个“后退”按钮可以返回主菜单)。
实施此工作流程的“最简单”方法是什么?我是否需要手动进行视图更改并为每个按钮实现单击处理程序,从而更改父组件的状态? (我在 Blend 中执行此操作,因此我试图避免在 VS 之外编写 C# 代码。)
如果我当前的设计(带状态的用户控件)使事情变得比需要的更困难,我愿意接受替代方案建议。 (这不是一个网页,只是一个常规应用程序,带有一些小屏幕导航+主屏幕内的子屏幕导航。)
I have a UserControl which I want to have 3 possible states:
-Main menu
-Config #1
-Config #2
(All three are UserControls with various buttons, textboxes, etc., and the parent UserControl's states set the child controls to visible/not visible depending on the current state.)
The main menu state has buttons to go to either of the 2 config states (and both of those states have a 'back' button to return to the main menu).
What is the 'easiest' way to implement this workflow? Do I need to do view changes manually and implement a click handler for each button, changing the state of the parent component? (I'm doing this in Blend so I'm trying to avoid having to write C# code outside of VS.)
If my current design (UserControl w/states) makes things harder than it needs to be, I'm open to alternative suggestions. (This is not a webpage, just a regular application with some minor screen navigation + sub-screen navigation within major screens.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 UserControl 上创建一个枚举(公开这三个值)属性,并使用 xaml 触发器来修改视图(参见下面的示例)。
为了根据菜单状态更改状态,您可以将所有菜单项单击事件处理为一个处理程序(或一个命令),传递适当的枚举作为命令参数或使用 Tag 属性,然后设置当前的 CurrentState 属性。
另一种方法是使用 StoryBoard 围绕各州进行循环。
示例(将 Window 替换为 UserControl,抱歉):
Xaml:
You could make an enum (that exposes these three values) property on your UserControl, and use xaml triggers to modify the view (look example bellow).
In order to change state according to menu state, you could address all the menuitems click event to one handler (or to one command) passing the appropriate enum as command parameter or with the Tag property, then set current CurrentState property.
Another way is using a StoryBoard to circle around the states.
Example (replace Window with UserControl, sorry):
Xaml: