有没有一种方法可以防止WPF页面被浏览掉? [英] Is there a way to prevent that a WPF page was navigated away?

查看:72
本文介绍了有没有一种方法可以防止WPF页面被浏览掉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建带有页面的WPF导航应用程序. 我想问用户离开页面时是否要保存更改.

I'm building a WPF navigation app, with pages. I want to ask the user if he want to save the changes when he leaves a page.

有办法吗?

推荐答案

注册NavigationService.Navigating事件.完成操作后,别忘了删除您的注册,因为NavigationService基本上会永远存在.

Register for the NavigationService.Navigating event. Don't forget to remove your registration when you are done, since NavigationService sticks around basically forever.

当您获得导航"事件并进行更改时,请显示一个MessageBox以便与用户确认或让他们有机会保存其数据.如果他们单击取消",则将e.Cancel = true设置为取消导航.

When you get the Navigating event and there are changes, show a MessageBox to confirm with the user or give them a chance to save their data. If they hit Cancel, set e.Cancel = true to cancel the navigation.

这篇关于有没有一种方法可以防止WPF页面被浏览掉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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