开发向导 UI - WPF [英] Developing wizard UI - WPF

查看:24
本文介绍了开发向导 UI - WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部在 WPF 中:

开发向导应用程序时,用户必须先回答一些简单的问题,然后才能进入主应用程序.然后,主应用程序会预填充从向导获得的信息.

Developing a wizard application, user has to answer a number of simple questions before brought to the main app. The main app is then prefilled with the information obtained from the wizard.

我从一个窗口开始,然后我计划向其中添加用户控件.主窗口的第一行是用户控件,然后是 Next 和 Previous 按钮来控制在第二行的控件之间移动.这样我就可以轻松控制在屏幕之间切换的逻辑,例如:

I started with a Window which I then planned to add usercontrols to. The main window would have the user control in the first row, then Next and Previous buttons to control moving between the controls in the second row. This way I could easily control the logic to switch between screens like:

WizardControl1.IsVisible = false;
WizardControl2.IsVisible = true;

但由于某种原因,用户控件没有 IsVisible 的设置器.万岁.

But for some reason, user controls do not have setter for IsVisible. Hurray.

然后我想我会为向导的每个部分使用单独的窗口.这种方法的问题是,现在当在两者之间切换时,窗口会在随机位置打开,并且通过在向导中使用 next 进行步进,下一个窗口会随机弹出,这确实令人分心和令人沮丧.

So then I thought I would just use seperate windows for each section of the wizard. The problem with this approach is that now when stepping between, the window opens in random positions, and by steppign through the wizard with next, the next window pops up randomly which is really distracting and frustrating.

那么我怎样才能正确地开发一个向导呢?我不明白为什么这这么难......不完全是火箭科学......在按下下一个/上一个后替换文本和控件并存储输入!

So how can I develop a wizard properly? I don't get why this is so hard...not exactly rocket science... replacing text and controls and storing input after pressing next/previous!

谢谢

推荐答案

我可能会使用数据绑定和模板选择器来解决这个问题.将向导表单绑定到WizardData"类,该类公开WizardPage"基类列表.

I'd probably aproach this using data binding and template selectors. Have the wizard form bind to a "WizardData" class, which exposes a list of "WizardPage" base classes.

WizardData 类可以公开定义表单上正确信息的属性,并为主页显示一个控件,该控件使用模板选择器根据特定向导页面的实际类型确定要显示的正确控件.

The WizardData class can expose properties defining the correct info on the forms, and display a control for the main page that uses a template selector to determine the proper control to display based on the actual type of the particular wizard page.

听起来确实比实际工作要多.它还为您提供代码和 UI 之间良好分离的好处(所有工作"都由 WizardData 和 WizardPage 类完成),以及独立于 UI 测试逻辑的能力.

It sounds like more work than it is, really. It also gives you the benefit of good separation between code and UI (all "work" is done by the WizardData and WizardPage classes), and the ability to test logic independent of the UI.

这也是一种非常 WPF/MVVM 解决问题的方法.

It's also a very WPF/MVVM way of approaching the problem.

这篇关于开发向导 UI - WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆