Good patterns for building a wizard?

前端 未结 2 2114
自闭症患者
自闭症患者 2021-02-09 07:13

I usually use a TabControl and somehow hide the tabs and navigate through them.

I am curious about other ways of doing this!!!

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 07:48

    This is a pretty involved topic; I built a fairly comprehensive Wizard control about two years ago for use in house and I remember it taking several weeks to get working exactly right.

    The basic elements are:

    • Header panel
    • Content panel
    • Action panel
    • Sidebar

    Both the content panel and action panel make use of the ParentControlDesigner to enable dropping controls. The content panel doesn't let you drop directly on it, instead it lets you drop on the active page (sub-panel). The action panel also has a "default" mode where it creates the standard 4 buttons (prev, next, cancel, finish). I mainly implemented the custom mode so I could skin it, i.e. using the DevEx buttons instead of the standard Winforms buttons.

    The header is basically static, it's a PictureBox and Label with the image, text, and font customizable. (By default the text is the same as the page title and the font is the control's font with bold style added).

    Then there are a set of data structures exposed by the API:

    • Steps (with name, title, etc., also specify whether or not they should be linked in sidebar)
    • Workflows (i.e. where you're taken to next based on your choices)
    • Validation events (both synchronous and asynchronous)
    • Actions (to be run before/after page change, button clicks, etc.)
    • Transition effects (I did these for fun, users like 'em)

    I put together a custom collection editor for the steps, which in turn create sub-panels for the content panel as explained above. Each panel is just added straight to the control collection, but only one is ever visible at a time based on the active step property. I remember that docking never seemed to work quite right so I had to override all of the resize methods. I never did get around to creating a smart tag to easily flip between pages, but the active page (or page index) can be chosen on the property grid.

    Then I also had to include a whole bunch of hooks for inserting any custom logic on individual pages. Hard to really get into much detail here without posting all the code.

    It's pretty time-consuming to properly design and test, but I don't remember using any whizbang design tricks, just had to approach the problem methodically, as mentioned, from the perspective of the individual UI elements (both runtime and design-time) and data structures and how they interact.

    Keep in mind all of this was for the purpose of creating a reusable Wizard component because we needed to develop about 10 of them for a particular app (and it's come in handy for other projects as well). If I just needed to hack together one quick wizard, I probably wouldn't go through all this trouble, I'd just do what you're doing - use a tab control and a few flow panels. Or better yet I'd use an off-the-shelf wizard control as are available in many Winforms libraries now, like the DX library.

提交回复
热议问题