{"id":61,"date":"2011-02-08T10:47:00","date_gmt":"2011-02-08T10:47:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2011\/02\/08\/mvvm-basic-binding-reflecting-multiple-targets\/"},"modified":"2011-02-08T10:47:00","modified_gmt":"2011-02-08T10:47:00","slug":"mvvm-basic-binding-reflecting-multiple-targets","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2011\/02\/08\/mvvm-basic-binding-reflecting-multiple-targets\/","title":{"rendered":"MVVM Basic Binding &#8211; reflecting multiple targets"},"content":{"rendered":"<div>I have a ViewModel implementing INotifyPropertyChanged interface and have at least two properties Value and IsChanged. When I bind two Textboxes to the Value on source and one check box to IsChanged property of the source I noticed that user changes to Value does not reflect the other target controls!<\/div>\n<div><\/div>\n<div>This behavior is due to the fact that my ViewModel was not provided as a field in my container ViewModel and rather it was created when needed.<\/div>\n<pre><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> PandViewModel PandViewModel<br \/>{<br \/>   <\/span><span style=\"color: #0000FF;\">get<\/span><span style=\"color: #000000;\"><br \/>   {<br \/>       <\/span><span style=\"color: #0000FF;\">return<\/span><span style=\"color: #000000;\"> listIndex &lt; <\/span><span style=\"color: #FF0000;\">0<\/span><span style=\"color: #000000;\"><br \/>       ? <\/span><span style=\"color: #0000FF;\">null<\/span><span style=\"color: #000000;\"><br \/>        : <\/span><span style=\"color: #0000FF;\">new<\/span><span style=\"color: #000000;\"> PandViewModel(panden[listIndex]);<br \/>   }<br \/>}<br \/><\/span><\/pre>\n<p>Moving the PandViewModel to a local field in this container class, or even putting it into an ObservableCollection will sort out the problem:    <\/p>\n<pre><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> PandViewModel PandViewModel<br \/>{<br \/>    <\/span><span style=\"color: #0000FF;\">get<\/span><span style=\"color: #000000;\"><br \/>    {<br \/>        <\/span><span style=\"color: #0000FF;\">return<\/span><span style=\"color: #000000;\"> listIndex &lt; <\/span><span style=\"color: #FF0000;\">0<\/span><span style=\"color: #000000;\"><br \/>        ? <\/span><span style=\"color: #0000FF;\">null<\/span><span style=\"color: #000000;\"><br \/>        : pandenVM[listIndex];<br \/>    }<br \/>}<\/span><\/pre>\n<p>See also a nice article over Binding on <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms752347.aspx\" title=\"Data Binding Overview\">MSDN<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a ViewModel implementing INotifyPropertyChanged interface and have at least two properties Value and IsChanged. When I bind two Textboxes to the Value on source and one check box to IsChanged property of the source I noticed that user changes to Value does not reflect the other target controls! This behavior is due to &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2011\/02\/08\/mvvm-basic-binding-reflecting-multiple-targets\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MVVM Basic Binding &#8211; reflecting multiple targets&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[57,58],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"I have a ViewModel implementing INotifyPropertyChanged interface and have at least two properties Value and IsChanged. When I bind two Textboxes to the Value on source and one check box to IsChanged property of the source I noticed that user changes to Value does not reflect the other target controls! This behavior is due to&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/61"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}