在实现 IConfirmNavigationRequest 的 View 中,我使用了四种导航过渡动画:ForwardIn、ForwardOut、BackwardIn 和 BackwardOut。
我正在使用 ConfirmNavigationRequest 等待 Out 转换完成后再导航。但是,根据导航的类型——使用 RequestNavigate() 向前或使用 GoBack() 向后——我想播放不同的 Storyboard:
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();
}
是否有任何准确且可预测的方法来检测从 NavigationContext 使用了哪种类型的导航?
编辑:我已经放弃使用 IConfirmNavigation 进行过渡,现在使用 AnimatedContentControl。
我不太喜欢它,但我正在发布一个事件来“警告”AnimatedContentControl 下一个导航应该使用特定的转换:
_eventAggregator.GetEvent<RegionTransitionEvent>().Publish(new RegionTransitionEventArgs { RegionName = RegionNames.NavRegion, RegionTransition = RegionTransitions.BackwardIn });
_regionManager.RequestNavigate(RegionNames.ContentRegion, ViewNames.ABC);
最佳答案
您可以在 View 或 View 模型中实现 INavigationAware
接口(interface)。
该接口(interface)将实现 3 个方法。
public interface INavigationAware
{
void OnNavigatedTo(NavigationContext navigationContext);
bool IsNavigationTarget(NavigationContext navigationContext);
void OnNavigatedFrom(NavigationContext navigationContext);
}
这将允许您确定它是否是往返某处的导航。您甚至可以确定导航来自哪个 View 。
关于c# - 检测是否在 NavigationContext 中调用了 GoBack(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707749/