views:

428

answers:

4

What is data contract (property class) and observable collection when, where and why to use these in context to silverlight please do explain in Details with Examples

++ Thanks and Regards Meetu Choudhary

+1  A: 

DataContractAttribute

ObservableCollection

Jason
+1  A: 

If you want certain data from database or from server then SL Application is dependent on WCF Service (or web service).

Now. if you use WCF Service then if you want to send any data other then let's say string, int, or other datatypes then you have to create data contract and then you can use that class as return type of any function which is called as operation contract

Observable collection is type of collection introduced in .Net 3.0, the advantage of using it is that if you will bind it with datagrid and if you have allowed user to change collections value then it will be automatically reflected in datagrid (something like twoway binding)

so, in nutshell

Custom class Property = DataMember Custom Class = DataContract

Function = OperationContract ServiceClass = ServiceContract

[DataContract]
public class LOVMetaData
{
    public LOVMetaData(decimal LId, string LHeader, string sql, bool selMode, string conString)
    {
     LOVId = LId; LOVHeader = LHeader; BasicSQL = sql; DefaultSelectionMode = selMode; ConnectionString = conString;
    }
    [DataMember]
    public decimal LOVId { get; set; }

    [DataMember]
    public string LOVHeader { get; set; }

    [DataMember]
    public string BasicSQL { get; set; }

    [DataMember]
    public bool DefaultSelectionMode { get; set; }

    [DataMember]
    public string ConnectionString { get; set; }    
}

[OperationContract]
public List<LOVMetaData> GetListofLOV(string filterString)
Harryboy
A: 

Link for your reference

http://www.codeproject.com/KB/silverlight/MySilverlightDataApp.aspx

Harryboy