WPF MVVM INotifyPropertyChanged Implementation – Model or ViewModel

The thing is that if you were following MVVM, you would have a BookViewModel for your Book model class. So you would have a INotifyPropertyChanged implementation on that view model. Exactly for that purpose MVVM exists (but not only). That being said, the INotifyPropertyChanged has to be implemented on view model classes, not models. UPDATE: … Read more

When to use a WPF Dependency Property versus INotifyPropertyChanged

There are a few approaches: 1. The dependency property While you using the dependency property it makes the most sense in elements-classes that have a visual appearance (UIElements). Pros: WPF do the logic stuff for you Some mechanism like animation use only dependency property ‘Fits’ ViewModel style Cons: You need to derive form DependencyObject A … Read more

Subscribe to INotifyPropertyChanged for nested (child) objects

since I wasn’t able to find a ready-to-use solution, I’ve done a custom implementation based on Pieters (and Marks) suggestions (thanks!). Using the classes, you will be notified about any change in a deep object tree, this works for any INotifyPropertyChanged implementing Types and INotifyCollectionChanged* implementing collections (Obviously, I’m using the ObservableCollection for that). I … Read more

How to raise PropertyChanged event without using string name

Added C# 6 Answer In C# 6 (and whatever version of VB comes with Visual Studio 2015) we have the nameof operator which makes things easier than ever. In my original answer below, I use a C# 5 feature (caller info attributes) to handle the common case of “self-changed” notifications. The nameof operator can be … Read more

Notify ObservableCollection when Item changes

The spot you have commented as // Code to trig on item change… will only trigger when the collection object gets changed, such as when it gets set to a new object, or set to null. With your current implementation of TrulyObservableCollection, to handle the property changed events of your collection, register something to the … Read more

In MVVM model should the model implement INotifyPropertyChanged interface?

Implementing INotifyPropertyChanged in Models is totally acceptable – Typically, the model implements the facilities that make it easy to bind to the view. This usually means it supports property and collection changed notification through the INotifyPropertyChanged and INotifyCollectionChanged interfaces. Models classes that represent collections of objects typically derive from the ObservableCollection<T> class, which provides an … Read more

Automatically INotifyPropertyChanged

EDIT: The author of NotifyPropertyWeaver has deprecated the tool in favor of the more general Fody. (A migration guide for people moving from weaver to fody is available.) A very convenient tool I’ve used for my projects is Notify Property Weaver Fody. It installs itself as a build step in your projects and during compilation … Read more