views:

303

answers:

1

I have a WPF application which was written in C#. This application hasn't been written with any particular design pattern in mind, but as I have learnt .NET I've realised that the MVVM model would be suitable. Thus, I'd like to start converting the code.

This will be the first time I've used MVVM, and whilst I'm willing to get stuck in, I'm finding it difficult to find solid MVVM examples online where an ADO.NET Data Service is the Model and XAML is the View. I'd like to look over some examples before setting off on the process of converting my own app to make sure I have correctly understood what I am doing!

Can anyone recommend a small (but non-trivial) example application with code which uses WPF, ADO.NET Data Services and the MVVM model?

+1  A: 

I recommend starting with any example that uses MVVM with WPF, and there are many. The fact is that a clean implementation of MVVM will not have any true data access code in it -- data access should be handled by another, abstracted layer (see http://stackoverflow.com/questions/1717621/mvvm-where-to-put-data-access-layer).

Work on designing a viewmodel that encapsulates all of the data and interaction that your (already existing) views require. Clean out your codebehind and get your view binding to your viewmodel.

Once you have that going, you can worry about how to get your objects to and from a persistence store, but the actual work of doing so does not belong in the M, V, or VM.

I know that there are tons of examples with data access right in the viewmodel or even the model, but those are meant to be quick illustrations that don't require tangents to address dependency injection, facades, etc.

Find any nontrivial example of MVVM in WPF, and when you get to the part where they deal directly with data access, remind yourself that at that point you'll be using an abstraction of persistence.

Jay