|
Hi Julie,
I believe that the approach you mentioned about using the invocation of the
InitializeComponent method in the ModuleAView to check if the view has been unloaded before could cause some problems in some scenarios. For example, if you have to instantiate the view more than once (e.g. in a tabbed control) the
InitializeComponent will be invoked in each view and this approach wouldn't work properly.
Another approach for this would be to simply check the if the view is in the region or not through the
Views property of the region.
Regarding the ModuleAViewModel, if it's declared as a singleton (based on my understanding) the view model will not be disposed as the container will hold a reference to the "singleton" instance. As there should only be one instance of the
ModuleAViewModel, this should not create a big memory load. However, if you wish to dispose the view model when the view is destroyed, it may make sense to declare the
ModuleAViewModel with the "NonShared" attribute.
Also, based on my understanding of your scenario, it seems like a common view-based navigation approach should work just fine. When you need to show a view in the shell and it already have another view, the previous view should be disposed
automatically if its KeepAlive method returns false.
You can find more about view-based navigation in the following link:
I hope you find this useful,
Damian Cherubini
http://blogs.southworks.net/dcherubini
|