Hi Peter,
After checking your code I believe the "problem" you are experiencing is related to when you are setting the keepAlive attribute of the views. Basically, the OnNavigatedFrom method is only executed in the view that is being "navigated from" or in other words, in the currently active view before the NavigationRequest. For example, if you have the following views in the TabControl and you navigate to an OtherView:
If you wish to "clear" the region when you inject a view from a different module, a possible approach could be to keep track of what module is being used and before navigating to a view from another module, remove all the views in the region. There are several approaches you can follow to do this. For example, you could use the EventAggregator and subscribe all the views (i.e. ListView, EditView, etc) to a certain event, so that in their corresponding handlers, they change the keepAlive attribute to false. Hence, before navigating to the other view, you can publish this event to set all the KeepAlive properties off all the views to false so that they are removed as expected.
I hope this helps,
Damian Cherubini
http://blogs.southworks.net/dcherubini
After checking your code I believe the "problem" you are experiencing is related to when you are setting the keepAlive attribute of the views. Basically, the OnNavigatedFrom method is only executed in the view that is being "navigated from" or in other words, in the currently active view before the NavigationRequest. For example, if you have the following views in the TabControl and you navigate to an OtherView:
- ListView
- EditView(1)
-
EditView(2) <-- Selected view
If you wish to "clear" the region when you inject a view from a different module, a possible approach could be to keep track of what module is being used and before navigating to a view from another module, remove all the views in the region. There are several approaches you can follow to do this. For example, you could use the EventAggregator and subscribe all the views (i.e. ListView, EditView, etc) to a certain event, so that in their corresponding handlers, they change the keepAlive attribute to false. Hence, before navigating to the other view, you can publish this event to set all the KeepAlive properties off all the views to false so that they are removed as expected.
I hope this helps,
Damian Cherubini
http://blogs.southworks.net/dcherubini