Hi Dani,
Based on my understanding, the RegionMemberLifetimeBehavior (which is in charge of removing the views with KeepAlive = false) only acts when the corresponding view is deactivated. Therefore, if you change the KeepAlive property of an already deactivated view, the behavior won't remove it even if the active view was changed. You can see this in the OnActiveViewsChanged method of the aforementioned behavior:
A possible approach to discard the unused views could be to manually remove them from the region. For example, when the view no longer is needed, instead of setting the KeepAlive property to false it could publish an event using the EventAggregator. The parent view model would be subscribed to this event and remove the corresponding view.
Another approach could be to change the aforementioned method of the behavior so that it would check the KeepAlive property of all the views and not only of the deactivated one. You can replace the original behavior overriding the ConfigureDefaultRegionBehaviors method of you Bootstrapper.
You can find more information about this in the following section of the Prism documentation: Appendix E - Extending Prism - Region Behaviors
Thanks,
Damian Cherubini
http://blogs.southworks.net/dcherubini
Based on my understanding, the RegionMemberLifetimeBehavior (which is in charge of removing the views with KeepAlive = false) only acts when the corresponding view is deactivated. Therefore, if you change the KeepAlive property of an already deactivated view, the behavior won't remove it even if the active view was changed. You can see this in the OnActiveViewsChanged method of the aforementioned behavior:
privatevoid OnActiveViewsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action != NotifyCollectionChangedAction.Remove) return; var inactiveViews = e.OldItems; foreach (var inactiveView in inactiveViews) { if (!ShouldKeepAlive(inactiveView)) { this.Region.Remove(inactiveView); } } }
Another approach could be to change the aforementioned method of the behavior so that it would check the KeepAlive property of all the views and not only of the deactivated one. You can replace the original behavior overriding the ConfigureDefaultRegionBehaviors method of you Bootstrapper.
You can find more information about this in the following section of the Prism documentation: Appendix E - Extending Prism - Region Behaviors
Thanks,
Damian Cherubini
http://blogs.southworks.net/dcherubini