视图如何取消 PRISM 中的导航请求? [英] How can a view cancel a navigation request in PRISM?

查看:128
本文介绍了视图如何取消 PRISM 中的导航请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现 INavigationAware 接口的视图.根据 MSDN http://msdn.microsoft.com/en-us/library/microsoft.practices.prism.regions.inavigationaware.onnavigatedfrom(v=pandp.40).aspx

I have a view that implements the INavigationAware interface. This interface has the OnNavigationFrom method that is, according to MSDN http://msdn.microsoft.com/en-us/library/microsoft.practices.prism.regions.inavigationaware.onnavigatedfrom(v=pandp.40).aspx,

当实现者被导航离开时调用.

Called when the implementer is being navigated away from.

现在,我想确保用户没有留下任何未保存的更改,如果有未保存的更改,请询问用户是否要保存它们.目前,我需要能够以某种方式取消该导航请求,以防用户想留下来继续编辑.

Now, I want to make sure that the user hasn't left any unsaved changes and if there are unsaved changes, ask the user if he wants to save them. At this moment I need to be able to cancel that navigation request somehow in case the user wants to stay and continue editing.

MSDN 上有关 INavigationAware 接口的文档没有说明应该如何使用该接口.

The documentation on the INavigationAware interface at MSDN doesn't say anything on how this interface is supposed to be used.

我可能是大错特错了,没有办法取消它,或者这个界面不适合那个.

I might be awfully wrong and there is no way to cancel it or this interface isn't meant for that.

无论如何,如果有人告诉我如何让用户留下并继续编辑已启动的导航请求,我将不胜感激.

Anyways, I appreciate if somebody tell me how I can make the user stay and continue editing one navigation request has been initiated.

推荐答案

我发现有另一个界面可以解决这个问题:"IConfirmNavigationRequest" 继承自 INavigationAware.它具有 ConfirmNavigationRequest 方法,该方法采用带有布尔参数的回调.如果我想取消导航请求,我会用 false 调用该回调,如果我想留下来,我会用 true 调用它:

I discovered there is another interface that does the trick: "IConfirmNavigationRequest" which inherits from INavigationAware. It has the ConfirmNavigationRequest method that takes a callback with a boolean argument. If I want to cancel the navigation request I call that callback with false, If I want to stay I call it with true:

continuationCallback(MessageBox.Show("Discard changes?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)

这样问题就解决了.感谢您的关注.

So the problem's solved. Thank you for your attention.

这篇关于视图如何取消 PRISM 中的导航请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆