Hi!
In the software I'm developing, I have a custom control that connects to an external event that warns the user when a certain setting has changed. I am using a weak event manager to connect to that event.
Let's say I open a window in my application that contains that user control. I finish using that window and close it. Then I go and change the setting that launches an event the user control connected to through a weak event manager. If the garbage collector hasn't already passed, the user control will get called even if it's in a closed window.
Of course, at some point, the garbage collector will pass and destroy that user control, but until it does, my user control still gets called by the external event.
I can make sure that those user controls disconnect themselves everywhere I use a window that uses that user control, but it's very troublesome to maintain.
If I was programming a WinForms Form, I'd simply disconnect from the event in the Dispose() function, but I can't really do that easily in WPF.
That user control is used in quite a lot of windows in my application, so I was wondering if there was a clean way to disconnect from that external event in all of my user control instances when the window is closed.