The first time you navigate to a view its IsNavigationTarget
method will not be checked, mainly because
doesn't need to use it at that point. The IsNavigationTarget
method is used to check if an instance of the required view that is deactivated inside the region is the target of the navigation request, according to the
parameters passed, etc. If no view of that type in the region return true
method, then Prism
will instead create a new instance of said view. At this point, there is no reason to check the
of the new view, as it has been explicitly created to be the navigation target.
When navigating using regions you will find that a view can be active
(it is being shown in the region,)
(it is not being shown, but is still kept alive by the region) or
from the region (the region no longer has a reference to the view). The function of the
is to specify if a view should also be removed from the region the moment it's deactivated, or should it be kept deactivated in the region so that it could be reused later. However, this is different from the lifetime
you can set in the container.
First of all, the effect of the IRegionMemberLifetime
is limited to the region containing the view only and does not have any effect on the instances of different regions. Second, the
will not ensure that the same instance of the view will be used for all the navigation requests in the region, meaning that there could be several instances of the view in the region at the same time. This is where
comes into play. By keeping the instance alive and returning
in the IsNavigationTarget
method, Prism will navigate to that existing view instead of creating a new one. Also, you can check the parameters passed in the navigation request before returning
, giving you the flexibility to decide if you want to reuse a view or create a new one.
I hope this helps to give a more in deep understanding of the navigation API used by Prism.