Windows Phone MVC - Released
I blogged a few weeks ago about the Windows Phone Essentials project, since then, I have started up the http://windowsphonefoundations.net/ website which is home to Windows Phone Essentials, Windows Phone MVC and Windows Phone MVP (and more projects in the future).
Features
This will change over time, so check out the change log.
- Strongly Typed Navigation
- Custom Shell, Navigator and Journal to give better control over navigation of WP7
- TransitionFrame comes out of the box, for nice navigation animations
- Ability to pass arguments in navigation, rather than uri query strings
- Modal Dialog support
- Easy access to Obscured and Activated events on your view model
- Full Testable! All major WP7 classes (WindowsPhoneFrame, WindowsPhoneApplication etc) all have Interfaces and are wrapped to allow you to test
- Some helpers around Async. Execute.AsyncPattern or Execute.AsyncPatternWithResult synchronise async calls
- Task/Chooser support, in a testable way
- Convention based Controller and View discovery
- Autofac Support Via an Extension
- Easy access to page or application transient storage
- Simple tombstoning support
Other cool stuff
Nice small/clean app.xaml/app.xaml.cs
<Application x:Class="HelloWindowsPhoneMVC.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WindowsPhoneMVC="clr-namespace:WindowsPhoneMVC;assembly=WindowsPhoneMVC"
UnhandledException="ApplicationUnhandledException">
<Application.ApplicationLifetimeObjects>
<WindowsPhoneMVC:NavigationApplication DefaultController="SomeController" DefaultAction="Blah" />
</Application.ApplicationLifetimeObjects>
</Application>
Type safe navigation
//Simple ICommand creation
ShowAboutDialogCommand = Controller<HomeController>().NavigationCommand(c => c.AboutDialog);
ShowAboutDialogCommand = Controller<HomeController>().NavigationCommand(c => c.AboutDialog, "A parameter");
//And normal navigation
Controller<HomeController>().NavigateTo(c => c.AboutDialog)
//And from xaml (not type safe)
<Button commands:Navigate.To="Home.About" Content="About" />
Easy lifecycle management
public SomeViewModel()
{
Transient(() => Name); //Will be restored after tombstone
}
Also have the IObscuredAware and IActivationAware to easily get notified about view activation/deactivation and when your app is obscured.
Autofac support via extension
Simple add the NuGet package for Autofac support, then change in your App.xaml from <WindowsPhoneMvc:NavigationApplication /> to <AutofacIntegration:AutofacNavigationApplication />
The NuGet package will create you a Autofac module to do all your registrations of services.
Check it out
Head over to http://windowsphonefoundations.net/windowsphonemvc or download via NuGet at http://nuget.org/List/Packages/WindowsPhoneMVC
Feedback welcome! I think it makes WP7 development really enjoyable.
Project templates on their way.
Comments
BigOM
I am really getting into the MVC framework. Its pretty good. The website defintely is pretty helpful although I know you want to put more examples up. If you could show us one thing which is simply how do you alert the view there has been an update to the Model so the display can make the necessary changes. I don't see how it can be done from the Controller, but I am sure I am looking over something. An example of how to do this would really help me along with a lot of others.
Jake Ginnivan
Basically with rich client, you only invoke controller actions for navigations or to show dialogues etc.
Within a view, just use the MVVM pattern and raise INotifyPropertyChanged events on the ViewModel to update the View.
It really should be Windows Phone MVC + MVVM, because that is what it is, but that is too long :P
I will write a follow up blog post about when to use controller actions and when to use MVVM within your app soon to clarify this. Thanks for the feedback!