This article is all about the implementation
of MVVM Pattern using Silverlight.
Checked out the following link : http://weblogs.asp.net/dwahlin/archive/2009/12/08/getting-started-with-the-mvvm-pattern-in-silverlight-applications.aspx
I just loved the Implementation by dwahlin. The implementation is very simple
and easy to code. I have modified the implementation to talk to database.
Created a new Silverlight Project named as MVVMBasic.
Created a new DataModel as shown below:
Created a new Silverlight Enabled WCF Service as shown below:
public
class
DataService
{
[OperationContract]
public List<Person>
GetPeople()
{
ProjectsDataEntities context =
new
ProjectsDataEntities();
var persons =
from person in
context.People
select person;
return persons.ToList();
}
[OperationContract]
public
OperationStatus UpdatePerson(Person p)
{
try
{
ProjectsDataEntities context
= new
ProjectsDataEntities();
Person currperson = (from
person in context.People
where
person.id == p.id
select
person).First();
currperson.LastName = p.LastName;
currperson.FirstName = p.FirstName;
context.SaveChanges();
return
new OperationStatus { Status =
true };
}
catch(Exception
ex)
{
return
new OperationStatus { Status =
false };
}
}
}
All the remainging things I have retained from the article by dwahlin.
Dwahlin returns the update status from the database in a nice way.


Join the conversation! Your thoughts help the community grow.