INavigationAware

Oct 30, 2012 at 5:17 PM

Hi,

what i would like to do is:

public class Controller1 

public void OnNavigatedTo(NavigationContext navigationContext)
        {
            var region = regionManager.Regions[RegionNames.MainRegion];
            Uri u = new Uri("DailyWorkTime",UriKind.Relative);
            region.RequestNavigate(u,NavigationCallback);
            
            
            region = regionManager.Regions[RegionNames.ToolbarRegion];
            var u1 = new Uri("TimeTrackingToolbar",UriKind.Relative);
            region.RequestNavigate(u1,NavigationCallback);
        }

.......

public bool KeepAlive {
            get {
                Console.WriteLine("TimeTracking KeepAlive");
                return false;
            }
        }

KeepAlive is called in Controller1 but not on the other views.

The creation of the Views and there models is working.

But, on navigating away from this views, there is no call to KeepAlive in both views.

(The interfaces are implemented)

What is the prefered method, using INavigationAware for the whole Application or, add Controls like Toolbar ostuff like this with Region.Add(view)  and use InavigarionAware only in some places.

Thanks

Peter

Developer
Oct 30, 2012 at 8:43 PM

Hi Peter,

I believe I am not understanding your scenario completely.

Based on my understanding, when implementing the IRegionMemberLifetime interface in a view (or view model) the KeepAlive property will be checked by the RegionMemberLifetimeBehavior when the aforementioned view is deactivated in a region. If that property returns false, the view is removed from the region automatically.

Hence, if your KeepAlive property of your views / view models are not being hit it could mean that the views (and view models) are not being deactivated from their corresponding region. For example, this could happen when using an ItemsControl as a region, as this kind of region can contain more than one active view at the same time. Then, if you "navigate away" from your views in that type of region, the views would still be active and the RegionMemberLifetimeBehavior will not try to check their KeepAlive property.

It could be helpful if you could provide us with more information about your scenario and what you are trying to achieve so that we can help you further with this.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Oct 31, 2012 at 7:37 AM
Edited Oct 31, 2012 at 7:41 AM

Hi,

<Then, if you "navigate away" from your views in that type of region, the views would still be active and the RegionMemberLifetimeBehavior will not try to check their KeepAlive property.

>

I will try this.

My App has Regions for SubMenu(depending on Module), Toolbar's, and 3 Regions for Menu's so that every Module can have it's own Toolbar's and menu's etc

Now, i try to handle all this stuff of adding and removing Toolbars and Menu's from Regions by using the INavigationAware and IRegionMemberLivetime Interfaces.

The reason for this is, i think that i have now trouble with cleaning up my Regions when a Module is changed.

 

Peter