I have a need to do some cleanup (unhooking events, etc.) in my child page control when navigating to another page. Could the Navigator.CreateAndShowControl() method be modified to call Dispose on the old content before assigning the new? Like this:
ContentPlaceholder.Content = newControl;
if (ContentPlaceholder.Content is IDisposable) (ContentPlaceholder.Content as IDisposable).Dispose(); ContentPlaceholder.Content = newControl;
This should be a non-breaking change.
In concept I think this is a good idea.
Specifically I don't like that particular approach, because it would prevent someone from maintaining a dictionary of "already open" items. In other words, blindly destroying view objects may help you, but may totally block other valuable UI models.
So what we probably need is a way for Navigator to notify you that a view is about to be "closed" so you can call dispose, or put it into your open-items list or whatever.
Copyright (c) Marimer LLC