hello,
i have a NavigationWindow that implements a wizard functionality, and a set of Page objects that represent the steps.
each Page uses a separate view model.
some of these view models spawn worker threads from their constructors. i terminate these threads when the view models are disposed of (they implement IDisposable).
furthermore, i assign these view models to the Pages' DataContext in the Pages' constructors, and dispose of the DataContext on the Unloaded event. i do this because i need to stop the worker threads.
all of this works fine as long as i do not want to navigate back in the wizard. but if i do, the page, since it has been unloaded before, does not have a DataContext anymore and does not show anything.
so, to fix that i need not dispose of the DataContext on Unloaded, and instead instruct the view model to start/stop its thread(s) when its owning window gets loaded/unloaded. i figure for that i need to introduce a couple of methods (say, Start() and Stop()) on the view model that would do that. and call these methods from the Pages' Initialized and Unloaded handlers.
but this is ugly. it is too complicated, the pages need to know to start/stop threads, otherwise it won't work. so i am looking for the right MVVM way to accomplish this.
please help konstantin