views:

83

answers:

3
+2  Q: 

MVC in Silverlight

When I discovered MVC (first with ASP.NET MVC), I thought it was the holy grail of software paradigms.

I recently started to dabble into Silverlight and noticed that the VS projects start off with pages similar to Forms (Web and Win) with code behinds and .xaml as the design.

Is there an equivalent to MVC in Silverlight (both for web and desktop applications)? Something supported by Microsoft (like ASP.NET MVC) where resources and help are plentiful?

I can't see myself returning to code-behinds after discovering MVC. Is this a naive idea when it comes to Silverlight because it's different than ASP.NET and can't easily implement MVC to it?

+3  A: 

Silverlight is pretty close to WPF, where the MVVM design pattern fits very well.

Unfortunately, the current incarnations of SL don't fully support MVVM because it lacks certain types (e.g. ICommand, IIRC), but with Silverlight 4, MVVM should be fully supported.

Mark Seemann
Actually SL3 supports ICommand (but without any concrete implementations)
Richard Szalay
I stand corrected. However, at PDC09 I got the impression that it wasn't there yet. At least they said: "SL 4 will have ICommand support"...
Mark Seemann
+2  A: 

There's no Microsoft-supported MVC framework for Silverlight. But MVC isn't a natural architecture for Silverlight applications anyway. The implied architecture of Silverlight and WPF is model - view - view model (MVVM), and this is supported directly in Silverlight via the data binding infrastructure. In MVVM, instead of having controllers talking to decoupled views, you create view model classes which encapsulate the data and behaviour, and the view realises itself from them using data binding.

The closest Microsoft has to a framework for Silverlight and WPF MVVM development is Prism. This is far from a complete solution, but you can supplement it with other third-party toolkits such as Josh Smith's MVVM Foundation.

itowlson
+1 for Prism (15 characters)
Richard Szalay
A: 

I have had some success using Laurent Bugnion's MVVMLight framework. http://mvvmlight.codeplex.com/

Brian Jimdar