11 Jul 2010 @ 1:35 PM 

In my solution, I have a Silverlight application using WCF services and a single DataModels.cs file with contents similar to the following. The only thing to remember is to add the WindowsBase reference to your WCF service project in order to use the same ObservableCollection<> template object.
(in my case, I put DataModels.cs in the WCF project, and created a virtual file link to it from the Silverlight project)

This is a sample of the code I use:
____________________________________________________ ____________________________________________

// <...other using statements...>
using System.Collections.ObjectModel; // ObservableCollection<> is added via WindowsBase (WindowsBase.dll).

public partial class CPPLoginState
    public bool Ok { get; set; }
    public string UserName { get; set; }
    public Int32 UserID { get; set; }
    public ObservableCollection Roles { get; set; }
public partial class CPPLoginState
    public CPPLoginState()
        Ok = false;
        UserName = "";
        UserID = 0;
        Roles = new ObservableCollection();


The trick here is in the Silverlight proxy’s use of the “partial” modifier for it’s class definitions. This allows “adding” code to them. :)

I must say, it only took one week working with Silverlight (from knowing nothing, not even WPF) and I’m almost done with a fairly complicated control library and host application. Silverlight + WCF really does == RAD development. :D

Posted By: James
Last Edit: 13 Jul 2010 @ 01:35 AM

Tags: , ,
Categories: Silverlight