Here is the situation: I have an editor app, that edits some hierarchical data. The data itself is held in ViewModel class, and View class is responsible to reflect changes in ViewModel. The main part of the View is ContentControl. When data changes in ViewModel, a hierarchical structure of controls is (re)generated and top-level control becomes the Content of the ContentControl. Of course, those hierarchical controls have bindings. Now it's time to close the editor. ViewModel reacts to command and clears the data. PropertyChanged is raised and the View is ready to react: it attempts to do
myContentControl.Content = null;
But this is where the pitfall is: WPF detaches hieararchy of controls from ContentControl's visual tree and re-evaluates bindings. But the data is already destroyed!
What should I do? Why WPF updates bindings on controls that go out of visual tree? Of course I can do additional check for nulls, but is there a way not to do binding at all on half-dead controls?