In a view that implements IConfirmNavigationRequest I am using four navigation transition animations: ForwardIn, ForwardOut, BackwardIn, and BackwardOut.
I'm using the ConfirmNavigationRequest to wait for the Out transition to finish before navigating. But, depending on the type of navigation - forward using RequestNavigate() or backward using GoBack() - I want to play different storyboards:
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
Storyboard storyboard;
if (navigationContext./* was RequestNavigate() or GoBack() called? */)
{
// GoBack navigation request.
storyboard = ((Storyboard)FindResource(RegionTransitions.BackwardOut));
}
else
{
// Forward navigation request.
storyboard = ((Storyboard)FindResource(RegionTransitions.ForwardOut));
}
storyboard.Completed += (sender, args) => continuationCallback(true);
storyboard.Begin();
}
Is there any accurate and predictable way to detect which type of navigation was used from the NavigationContext?
Edit: I've since abandoned using IConfirmNavigation for transitions and am now using an AnimatedContentControl.
I don't really like it, but I'm publishing an event to 'warn' the AnimatedContentControl that the next navigation should use a specific transition:
_eventAggregator.GetEvent<RegionTransitionEvent>().Publish(new RegionTransitionEventArgs { RegionName = RegionNames.NavRegion, RegionTransition = RegionTransitions.BackwardIn });
_regionManager.RequestNavigate(RegionNames.ContentRegion, ViewNames.ABC);
You can implement the INavigationAware interface in your view or viewmodel.
This interface will implement 3 methods.
public interface INavigationAware
{
void OnNavigatedTo(NavigationContext navigationContext);
bool IsNavigationTarget(NavigationContext navigationContext);
void OnNavigatedFrom(NavigationContext navigationContext);
}
the will allow you to determine if it is navigation to and from somewhere. you can even determine of which view the navigation comes from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With