WPF 中的自定义向导控件添加和删除 UserControls?
如何最好地在 WPF 中创建 Wizard 控件。我的塔克是;首先我有一个向导控制器用户控件,其中包含两个按钮,即“后退”和“下一步”,然后我从另外两个用户控件开始,其中包含供用户填写的表单,然后单击下一步到下一个表单等...我想要什么我要知道的是如何插入这个用户控件并在进入下一个表单之前验证我当前的对象。我可以使用什么来获取下一个和上一个事件,或者是否有更好的解决方案?
How best can I create a Wizard control in WPF. My tak is; first I have a Wizard Controller UserControl, that contains two buttons, i.e. Back and Next, then I have start off with two other UserControls with forms for users to fill in and click next step to the next form etc... What I woud like to know is how I could inserted this usercontrols and validate my current object before going to the next form. What can I use to get the next and previous events or is there a better solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我仍在学习 WPF,并且正在研究 WinForm 项目 atm,对于本文中的任何 WinForm 参考资料深表歉意。
向导控件可以包含对向导将显示的每个用户控件的引用。向导会将所有这些控件添加到其自身
controls.add(_userControl1)
中。每个控件的可见属性都设置为 false。向导还可以包含一个带有控件名称列表的私有
enum
,即向导控件保留对当前显示控件的引用
CurrentControl _currentControl = CurrentControl._MyControl1;
有一个UpdateDisplay () 方法,该方法基于 _currentControl 只会使该控件可见。然后,当您单击“上一个”/“下一个”按钮时,它会根据其当前值更新 _currentControl 变量,调用 UpdateDisplay() 以显示下一个控件。
这样,您就可以引用所有用户控件(以及它们包含的数据),因此您可以验证内容,并且您的向导可以使用向导上的按钮以及向导中的逻辑来前后移动它们。显示和隐藏控件的向导。
Im still learning WPF, and am working on WinForm project atm, so sorry for any WinForm references in this.
The wizard control could contain a reference to each usercontrol the wizard will display. The wizard will add all these controls to itsself
controls.add(_userControl1)
. Each control has its visible property set to false.The wizard could also contain a private
enum
with a list of control names, i.e.Wizard control keeps a reference to the current displayed control
CurrentControl _currentControl = CurrentControl._MyControl1;
Have a UpdateDisplay() method, which based on the _currentControl will only make that one control visible.Then when you click on Prev/next buttons, it updates the _currentControl varible based on its current value, calls UpdateDisplay() to show th enext control.
This way you have a reference to all your user controls (and thus the data they contain), and thus you can validate the content and your wizard can go back and forward through them by using the buttons on the wizard, and the logic in the wizard showing and hiding the controls.
您可能对 WPF 应用程序框架 (WAF) 的 EmailClient (ViewModel) 示例应用程序感兴趣)。它展示了如何使用模型-视图-视图模型模式创建向导,并且包含验证逻辑,当用户输入无效时,该逻辑将禁用“下一步”按钮。
You might be interested in the EmailClient (ViewModel) sample application of the WPF Application Framework (WAF). It shows how to create a Wizard with the Model-View-ViewModel pattern and it contains validation logic which disables the Next button when the user input is not valid.