{"id":21,"date":"2014-08-24T09:40:00","date_gmt":"2014-08-24T09:40:00","guid":{"rendered":""},"modified":"2016-01-30T23:28:36","modified_gmt":"2016-01-30T23:28:36","slug":"inotifypropertychange-notifying-about-change-of-all-properties-at-once","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2014\/08\/24\/inotifypropertychange-notifying-about-change-of-all-properties-at-once\/","title":{"rendered":"INotifyPropertyChange &#8211; notifying about change of all properties at once"},"content":{"rendered":"<p>Today, working on a new feature for my pet project, I realized that I have to notify the view, that all properties in view model have changed. The most obvious way to achieve that would, of course be to rise <i>PropertyChange<\/i> event a bunch of times.<\/p>\n<pre lang=\"csharp\">\r\nprotected virtual void OnPropertyChanged(Expression<Func<object>> propertyExpression)\r\n{\r\n   \/\/..\r\n   \/\/implementation\r\n   \/\/..\r\n}\r\n\r\nprotected virtual void OnPropertyChanged(string propertyName)\r\n{\r\n   \/\/..\r\n   \/\/implementation\r\n   \/\/..\r\n}\r\n\r\npublic void Refresh()\r\n{\r\n   OnPropertyChanged(() => FirstProperty);\r\n   OnPropertyChanged(() => SecondProperty);\r\n   OnPropertyChanged(() => ThirdProperty);\r\n   \/\/and so on ...\r\n}\r\n<\/pre>\n<p>This is good solution for one time usage, however I was interested in something more general, something which could be extracted to base view model. Fortunately, it turns out that there is a simple trick to do that. All You have to do is use an empty string or null as a property name. So in my case this comes down to this one-liner<\/p>\n<pre lang=\"csharp\">\r\npublic void Refresh()\r\n{\r\n   OnPropertyChanged(string.Empty);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today, working on a new feature for my pet project, I realized that I have to notify the view, that all properties in view model have changed. The most obvious way to achieve that would, of course be to rise PropertyChange event a bunch of times. protected virtual void OnPropertyChanged(Expression propertyExpression) { \/\/.. \/\/implementation \/\/.. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,43,44,45],"tags":[188,189,190,191],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-inotifypropertychanged","category-mvvm","category-silverlight","category-wpf","tag-inotifypropertychanged","tag-mvvm","tag-silverlight","tag-wpf"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":3,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}