Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement a Wizard form a Windows Mobile application?

I am a bit new to Windows Mobile (with C# and the compact framework) development, so I am kind of unsure how to do this. The user has to go through several pages of information in a wizard-like manner. At the start there is a login window.

How would I go about and implement this? Would I just have different User Controls for each page and create/show and destroy/hide them on request? Or do I need to create different forms and somehow show those?

EDIT (from a different user than the OP)

Since I also have not found a good solution to this and the links from some of the answers are not usable in Windows Mobile 6.5 I am starting a bounty

These looked promising but can' be built for mobile 6.5

http://weblogs.asp.net/justin_rogers/articles/117859.aspx

http://www.codeproject.com/KB/dialog/WizardForm.aspx

http://www.codeproject.com/KB/miscctrl/DesignTimeWizard.aspx

http://winformswizard.codeplex.com/

http://www.differentpla.net/content/2005/02/implementing-wizard-c (same as above but earlier work)

like image 544
pbean Avatar asked Mar 12 '10 15:03

pbean


2 Answers

I would use a TabControl to "simulate" a wizard (note that I have not personally used a TabControl in a Windows Mobile/Compact FrameWork context, but it is listed officially by Microsoft as part of the FrameWork for "Windows CE, Windows Mobile for Pocket PC." See :TabControl

In WinForms there's an easy trick to hide the tabs if you want to create a wizard-like user-experience: in the Form 'Load event set the Region of the Tabcontrol to the DisplayRectangle of the TabControl.

tabControl1.Region = new Region(tabControl1.DisplayRectangle);

If that works for you, it will save you a lot of trouble of moving 'UserControls or 'Panels around, and you can design your TabPages in visual mode at design-time, then control navigation from TabPage to TabPage in whatever way you think best.

You might want to "snapshot" the original Region of the TabControl in the Form 'Load event if you ever want to restore the Tabs into view.

Here's a quick example of one way to do that : a kind of "one-way" start-to-finish model :

Define a Dictionary where each Key is a TabPage, and the boolean value of each Key entry controls whether or not you will allow the user to navigate to that TabPage.

// allocate the Dictionary
Dictionary<TabPage, bool> CanNavigateDict = new Dictionary<TabPage, bool>();

You'll want to "prepare that Dictionary by doing something like this in the Form Load event :

foreach (TabPage theTPage in tabControl1.TabPages)
{
    CanNavigateDict.Add(theTPage, false); 
}

// show the first TabPage
tabControl1.SelectedTab = tabPage1;

Navigation control in this model means you need to set the boolean value of the next TabPage to 'true when, through whatever means, you've satisfied your criteria for completion of the current page: Sample

// sample of how you control navigation in the TabControl
// by using the CanNavigate Dictionary in the TabControl 'Selecting event
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
  e.Cancel = ! CanNavigateDict[e.TabPage];
}
like image 177
BillW Avatar answered Oct 12 '22 22:10

BillW


I'd be highly inclined to use a DI/IoC container for this (specifically I'd use this one, but pretty much any of them should work).

I'd create a MainForm that is the app's "host". On that MainForm I'd place either a DeckWorkspace or a TabWorkspace, depending on how you want the user to be allowed to navigate. If you only want to allow forward/back, I'd go with a deckworkspace. If they are allowed to jump several steps, a TabWorkspace would probably make more sense.

I'd then add a couple of buttons to the MainForm that would be the navigation buttons.

I'd then create a SmartPart (view) for each of the wizard pages. Beneath the hood these are UserControls, but they are something the Wor4kspaces know how to use.

I'd then create a WizardService that would have a state machine in it for what is valid for navigation, what SmartParts get shown for a forward/back, etc.

I'd then create presenters for each of the SmartParts to wire the Views to the WizardService or just a single Presenter for the whole thing. This would greatly depend on the complexity of the wizard data and how the data from step to step are related.

Next I'd wire up events for the navigation buttons. Those events would go to the WizardService, which would handle determining where we need to navigate to and contact the presenter, which in turn would show and populate the appropriate view.

EDIT

I've put together a solid working example of a Wizard running on WinMo/WEH. The exact same code would work fine on Windows CE or even on the desktop. See my blog for a bit of an explanation or pull the code right from the Codeplex project's changesets.

like image 31
ctacke Avatar answered Oct 12 '22 21:10

ctacke