开发向导 UI - WPF

Developing wizard UI - WPF(开发向导 UI - WPF)
本文介绍了开发向导 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)