In Silverlight for Windows Phone I have several view models that are disposable and perform necessary cleanup, like event unsubscribing from longer-living services, in Dispose().
When I navigate back in the view stack and the most recent view model have done its deed to completion, I need to call Dispose() on it.
What good patterns of doing this in a structured way are there?
You could make a Blend Behavior or attached property that listens for the Unloaded event , and then calls Dispose()
on the DataContext
of the object if it's IDisposable
. This could then be attached to your Views as appropriate.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.