Caliburn.Micro for Newbies Who Want to Write Clean WP7 Apps - Part 1: How to Configure a New Project With Folders
- minimal code-behind
- minimal databinding
- clean separation between views and view-models (making unit testing easier)
- simplified navigation between views
(There are many more benefits, but they are more esoteric than my brain can assimilate for now.)
Much of the simplification is achieved by "convention over configuration".
This series of posts is my journey to understanding Caliburn.Micro for a real Win Phone 7 project. I am not a Caliburn.Micro ninja -- quite the opposite. I take my hat off to Rob Eisenberg for the framework he and his colleagues are creating. But, despite reading his documentation, and source code, I am a slow learner when it comes to putting into practical use. Thus, comments and corrections are encouraged!
So many introductory articles are "Hello World" apps that are TOO trivial. I want a VS2010 solution layout that I can use as a standard starting point for new apps, that encourages me to be a tidy coder.
- You have heard about Caliburn.Micro. (If not, read the Introductory Page)
- You have obtained the source code. (Otherwise, I'll wait while you sort that out too. You need a certain level of determination to make this work!)
- You have downloaded the RTM developer tools for WP7.
How to start a new Caliburn.Micro WP7 project in Visual Studio?
- File-NewProject WindowsPhone7 app.
- Add as an Existing Project your Caliburn.Micro WP7 source code project.
- To your WP7 project add a Project Reference to the Caliburn.Micro project.
- To your WP7 project add Model, Views and ViewModels folders.
- Delete the default startup page, MainPage.xaml, as it's in the wrong place.
- In the Views folder, create a new WP7 page as your startup screen and call it, say, ShellView.xaml.
- In the ViewModels folder, create a new class and call it, say, ShellViewModel.cs. Inherit from a suitable Caliburn.Micro class, eg Screen.
- Open the WMAppManifest.xml file in the Properties folder. Change the DefaultTask NavigationPage from MainPage.xaml to Views/ShellView.xaml.
- Build the app and check that it runs the default page.
- Add a Model folder to your project.
Now you have a tidy structure for your application, with separate folders for model, view and viewmodel files.
Important conventions to note so far:
- a view can be located from a viewmodel via convention: the name of the view (ignoring the file extension) is the name of the viewmodel, but with all instances of the word "Model" removed. Eg, "ViewModels/ShellViewModel.cs" corresponds to the view, "Views/ShellView.xaml".
Coming up next (when I have time)...
Part 2. Navigating between views
Other related posts:
NuPeek - a local NuGet and Symbol Server for .NET
Bitwise testing in C#
Seven Laws of User Interface (UI) Design
Add a comment
Please note: comments that are inappropriate or promotional in nature will be deleted.
E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.
Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and placed in the moderation queue for the blog owner's approval.