Any Notification when the view getting deactivated ?

Topics: Prism v4 - WPF 4
Sep 20, 2013 at 9:49 AM
Hi ,

Can anyone know about whether any event raised when the view is getting deactivated ?

Otherwise Is there any way to find the notification when the view is getting deactivated ?

Thanks and regards,
Sep 20, 2013 at 3:08 PM
Hi sivalingam,

Each region has a collection of ActiveViews which raises a collectionChanged event when an active View changes (the view is deactivated or removed), or a new View becomes Active. You can subscribe to this event as follows:
this.regionManager.Regions["RegionName"].ActiveViews.CollectionChanged += ActiveViews_OnCollectionChanged;
Therefore, you can implement an EventHandler by verifying if the corresponding View is contained in the collection or not. Please note that the collection has the current active views, so you would want that the concerned View is not contained on it. For example, you can do as follows:
void ActiveViews_OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    if ( sender.Contains(Container.Resolve<View>()) )
          // View is active
It´s important to notice that this implementation would also work when the View being evaluated was not Active and the event was raised by any other view.

An alternative to this approach would be to make the specified View or ViewModel implements the IActiveAware interface, and raise the IsActiveChanged event from the setter method of the IsActive property.

I hope this helps,

Gabriel Ostrowsky