What is a good pattern for binding a collection of objects coming from WCF, in Silverlight?
Posted
by Krishna
on Stack Overflow
See other posts from Stack Overflow
or by Krishna
Published on 2010-04-23T11:31:20Z
Indexed on
2010/04/23
11:33 UTC
Read the original article
Hit count: 447
Hi there,
I've got a question about a Silverlight WCF Databinding pattern:
There are many examples about how to bind data using {Binding} expressions in XAML, how to make async calls to a WCF service, set the DataContext property of a element in the UI, how to use ObservableCollections and INotifyPropertyChanged, INotifyCollectionChanged and so on.
Background: I'm using the MVVM pattern, and have a Silverlight ItemsControl, whose ItemsSource is set to an ObservableCollection property on my ViewModel object. My view is of course the XAML which has the {Binding}. Say the model object is called 'Metric'. My ViewModel periodically makes calls to a WCF service that returns ObservableCollection. MetricInfo is the data transfer object (DTO).
My question is two-fold:
- Is there any way to avoid copying each property of MetricInfo to the model class - Metric?
- When the WCF calls completes, is there any way to make sure I sync the items which are in both my local ObservableCollection and the result of the WCF call - without having to first clear out all the items in the local collection and then add all the ones from the WCF call result?
thanks, Krishna
© Stack Overflow or respective owner