Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does WPF subscribe to the PropertyChanged event?

I have a ClassA with an ObservableCollection property, that implements the INotifyPropertyChanged interface

on my window codebehind I have declared a ClassA variable, and initialize it in the Main() method.

i'd expect that variable.PropertyChanged would have a WPF event wired to it, but apparently the PropertyChanged event remains null

like image 857
thmsn Avatar asked Aug 26 '09 19:08

thmsn


2 Answers

WPF will subscribe to the PropertyChanged event when you bind to your object. This is the core way that databinding works.

It actually does this via the PropertyChangedEventManager using the WeakEvent pattern in WPF.

like image 78
Reed Copsey Avatar answered Sep 20 '22 21:09

Reed Copsey


I'm not sure if this exactly answers your question, but I had similar experiences, and blogged about it here.

Essentially, make sure the DataContext is not null when the binding occurs, such that PropertyChanged events can get back to the UI...

like image 20
kiwipom Avatar answered Sep 20 '22 21:09

kiwipom