Another Silverlight navigation request

Another Silverlight navigation request

Old forum URL: forums.lhotka.net/forums/t/5707.aspx


dnwheeler posted on Thursday, October 30, 2008

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:

Old:

ContentPlaceholder.Content = newControl;

New:

if (ContentPlaceholder.Content is IDisposable)
  (ContentPlaceholder.Content as IDisposable).Dispose();
ContentPlaceholder.Content = newControl;

This should be a non-breaking change.

--Doug

RockfordLhotka replied on Thursday, October 30, 2008

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