Long, long ago I wrote an article for MSDN on creating a multi-Form CF application that used a Form Stack. Since we all tend to grow and learn as developers, we find different ways to do things (and generally we scoff at code we wrote years before as inferior crap).
Well Peter Nowak is giving a presentation of the OpenNETCF.IoC framework next week and I decided that a sample of using the UI elements of the library (Workspaces, SmartParts, etc) might be handy and so I decided to rewrite the Form Stack following my latest thinking. Basically the idea is to allow a user to navigate through Forms (actually Views – you are separating your Views from the Model, right?) like you would on a browser. You can move forward and back as well as “adding” to the end or top of the stack. We also don’t want to be constantly creating new instances of the View classes because we like applications to perform well.
Here’s a look at the new application (yes, I know it’s “developer ugly” but this is about architecture, not aesthetics):
You can see the stack in the list, and our current position is noted by the asterisk. “Fwd” will move down to View B, “Back” will move up to Form A, or you can push a new A or B onto the stack at the current location, which will truncate everything currently above (after) the current position. Again, think of how your browser works. It’s important to know, also, that there are only 3 total View instances created at this point (one of each specific type).
The code for this application is in source control over at the OpenNETCF.IoC Framework Codeplex site. You’ll notice it’s called FormStackCS, hinting that there may be a FormStackVB coming. If you’d like to volunteer to do that port, by all means let me know (meaning don’t hold your breath waiting for me to do it).