views:

80

answers:

4

I am working on Silverlight 3.0 and currently using code-behind in my Views. I would like to implement the MV(VM) pattern into my project as the project is growing. I have seen some WPF projects where the code-behind has NO CODE except for the InitializeComponent method, which I believe is the right way to go and just looks clean. Is this possible in Silverlight 3.0, that is, no code-behind?

Can anyone point me to some good Silverlight (3.0) MV(VM) tutorials / articles?

+1  A: 

Without using some additional framework, Silverlight 3 does not support what you saw in WPF. Specifically, full Commanding support. Silverlight 4 has included Commanding for Buttons, which is a start.

You can look into other frameworks that provides this feature set, like Prism. This will get you along the right path, but I'm sure there are other options.

greglev
To the down-voter, please explain why? Is there a way to use Silverlight 3 out-of-box without having any code-behind for events? How do you pass into the VM? Thanks!(this of course is assuming you don't write your own framework/reinvent the wheel)
greglev
@greglev: I did not down-vote you, but I can say with certainty that I have been doing MVVM with little to no code-behind since Silverlight 2 out of the box. It does require you to write some attached behaviors, which is pretty easy, for binding commands. BUT, you don't need a 3rd party framework to do it.
Brian Genisio
Nice, Thanks Brian.
greglev
+1  A: 

You can follow the MVVM pattern for Silverlight 3 applications without using a framework. However, it is much easier to use one of the many MVVM frameworks out there. Here are a few good ones:

I'd recommend not using Prism as it is more complicated than it needs to be.

Bryant
+1  A: 

Other options include things like MVVM Light, which is lighter weight alternative to Prism for things like handling events and commands, however Prism does have a lot of functionality (and the Prism 4 talk has that sounding like a good option when it gets released).

One good community site to check out is the Composite Development Patterns Community, which was newly started but has an excellent goal of collecting articles and other help for working with development patterns like MVVM.

Lastly, John Papa gives a great overview of MVVM, limited to links so head to Google and look up "John Papa MVVM". :)

One thing to consider though, resources for SL3 aren't going to be as valuable as those for SL4, which opens up additional options for framework based commanding (ICommand that greglev mentioned), although it isn't still the full command support from WPF.

Evan Hutnick
+1  A: 

Jesse Liberty has a good primer on MVVM also using Behaviors for wiring events.

http://stackoverflow.com/questions/2790073/silverlight-and-mvvm-pattern-no-code-behind-is-this-possible

76mel