tag:blogger.com,1999:blog-8985156687507385407.post6274172218255900054..comments2012-07-06T03:22:56.647-07:00Comments on Kiran Kumar: Silverlight - Property Value Synchronization between Two View ModelsKiran Kumar Ghttp://www.blogger.com/profile/16177138782308325448noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8985156687507385407.post-37618837164748143822012-01-03T22:45:35.577-08:002012-01-03T22:45:35.577-08:00Hi Leo, appreciate your comment.
Observer pattern...Hi Leo, appreciate your comment.<br /><br />Observer pattern is ideal when you want to notify changes of subject (Originator) to Observers ( targets). Upon what events notification need to be raised is left to discretion of subject and upon occurence of those notifications what needs to be done by Observers is left to Observers code. To implement this observer pattern subject & observer both need to have code implementing this pattern.<br /><br />But the scenario I tried to address here is specific to syncing properties between classes, i.e I know before hand that when a property is changed I need to get notifications, INotifyPropertyChanged supports those notifications (Subject in observer pattern is already supported/implemented by all classes). And also I know that Observer(target) need to sync it's respective property with new value.<br />As this is common pattern I see across classes I dont want to repeat same code across observers. I abstracted this to a separate class which listens to property change notifications and updates target classes properties in a generic way. Instead of setting properties, you can also do other things, as Sync class takes functions which need to be called when property changes occur in subjects.<br /><br />Current design supports multiple target classes scenario(syncing multiple view models). All you need to do is to create Multiple sync objects for each source(subject/viewmodel) and target (observer/viewmodel) combination. Think of this as analogus to Binding object which sync two properties. At the time of writing this blog, Binding object supports only Dependency properties as targets. Otherwise sync class would have used Binding object internally to sync properties. But I think now i.e SL 5.0, Binding object supports any properties, I didn't verified this for sure.Kiran Kumar Ghttps://www.blogger.com/profile/16177138782308325448noreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-67960346908479380352012-01-03T13:19:50.800-08:002012-01-03T13:19:50.800-08:00Hi Kumar, what happens if I have more than 1 viewm...Hi Kumar, what happens if I have more than 1 viewmodel listening to the Subject (Observer pattern)?<br /><br />You're only implementing T,T1. Do we have to create our own events still or we could just add more T2, T3 and modify your stuff? I think if we modified your existing code then that would take more code to do rather than creating own event subscribersLeohttp://luisleo.netnoreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-52661260754664344072010-08-18T04:43:25.935-07:002010-08-18T04:43:25.935-07:00This comment has been removed by the author.Kiran Kumar Ghttps://www.blogger.com/profile/16177138782308325448noreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-68536386533795055292010-08-18T04:40:30.665-07:002010-08-18T04:40:30.665-07:00I updated link location in article.
"http://...I updated link location in article.<br /><br />"http://cid-b345d108a9d3464d.office.live.com/self.aspx/.Public/SyncEngine.zip"<br /><br />Thank you for informing this glitch. I Appreciate it.Kiran Kumar Ghttps://www.blogger.com/profile/16177138782308325448noreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-73699252826745376242010-08-18T04:31:42.075-07:002010-08-18T04:31:42.075-07:00sample application
download link 404 not foundsample application<br /><br />download link 404 not foundAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-67090643581558867722010-08-18T02:23:27.318-07:002010-08-18T02:23:27.318-07:00You wrote an intresting article. We are using some...You wrote an intresting article. We are using some sort of similar method you had explained. We ran into a situation that few property values in two viewmodels(in general two classes implementing INotifyPropertyChanged) event need to be in sync. I am addressing scenario of synching two properties in two view models and those are not necessarily master and child instead they even can be siblings, and both might need to exist without another.<br />Thanks for your comment.Kiran Kumar Ghttps://www.blogger.com/profile/16177138782308325448noreply@blogger.comtag:blogger.com,1999:blog-8985156687507385407.post-53949398831732608912010-08-17T10:55:12.603-07:002010-08-17T10:55:12.603-07:00If Both View Models are on the screen at the same ...If Both View Models are on the screen at the same time I use this method:<br /><br />http://www.codeproject.com/KB/silverlight/VMCommunication.aspx<br /><br />Is there a situation that your solution covers that is not covered that that method?Unknownhttps://www.blogger.com/profile/12232883992927663957noreply@blogger.com