It looks like WPF doesn't always call the registered PropertyChangedCallback procedure of a DependencyProperty. Even if we manually raise PropertyChanged event from the VM, WPF seems to actually evaluate the old and new value of the property before deciding if it would call the callback. So my questions here are:
My ViewModel has a public property define as follows:
Public ReadOnly Property CurrentSelection() As ObservableCollection(Of Object)
My View binds to this property like this (BetterPropertyGrid is a UserControl that wraps a WinForms PropertyGrid in it and has a DependencyProperty named SelectedObjects):
<bd:BetterPropertyGrid SelectedObjects="{Binding CurrentSelection}" />
Now whenever my ViewModel adds or removes objects from CurrentSelection, I manually raise PropertyChanged("CurrentSelection"), but it doesn't seem to update my View.
WPF checks if the property value is actually different from what is was before the change notification was raised. In your case, the same collection instance is returned from the view model property getter, hence the change has no effect.
"Why is this so?": Because old and new property value are equal. In the PropertyChangedEventArgs passed to your PropertyChangedCallback e.OldValue and e.NewValue would reference the same collection instance.
"What is the workaround?": Register a handler for the INotifyCollectionChanged.CollectionChanged event of the SelectedObjects property value, as shown in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With