Possible ActionMessage bug or understanding bug

Nov 10, 2010 at 12:40 AM

I have a view model that represents a screen. It is a singleton (resolved using MEF). I have a Screen Conductor that manages a list of these different view model screens. The user clicks on a button which sets the ActiveItem of the conductor to whichever screen he/she clicked on. Pretty straight forward stuff. What I am noticing is that ActionMessage.PrepareContext is called every time one of my Views load via the ActionMessage.ElementLoaded callback. So when the ActiveItem is changed on my conductor a new View gets created and PrepareContext gets called, so far so good. However PrepareContext  has a line:

        inpc.PropertyChanged += handler;
that subscribes to my view model singleton for each ActionMessage in my view every time the view is loaded. The net effect is that every time the user navigates away and back again I am getting multiple notifications for the various CanXXX handlers on my View Model.
So after a few minutes these ActionMessage callbacks could be called 10 times for each ActionMessage dispatch. The issue is that when the view is Unloaded the subscriptions are left dangling, it appears that the Detaching event is never called:
	context.Message.Detaching += delegate { inpc.PropertyChanged -= handler; };
Any thoughts on this? Am I not doing something quite correctly?

Regards,
Sandy
Coordinator
Nov 10, 2010 at 2:54 AM

Would you be willing to email me a small sample that reproduces the problem? That would help me squash the bug or make a recommendation on how to work around it. Feel free to send it to robertheisenberg at hotmail dot com

Nov 14, 2010 at 7:47 PM

Just wanted to confirm you got the project that reproduces this issue.