I have a WPF application that contains some Windows with few UserControls and a Coordinator object. The window and all its user controls are pointing to an object, which instance is in the Coordinator, by their DataContext.
The problem is that I want to change this object (e.g. create new object()) in the Coordinator but I want all the DataContexts to point to the new object.
I tried to send the object by ref to the window constructor but it didn’t help.
Any idea about how can I rewrite the memory location that all pointers are pointing to?
(I don’t want to replace the properties in object since it’s a lot of work nor to use a middle object that points to the replaced object)
It’s normal because, even if you change the object the reference is pointing to, your user controls have no way to know that something has changed : you have to notify them.
You have two solutions to do so :
make your Coordinator implement INotifyPropertyChanged and raise NotifyPropertyChanged when the object reference changes,
make your object available via a DependencyProperty and use a property wrapper.
When changed the DependencyProperty will automatically notify its observers.