Silverlight 在保存之前停止页面关闭 [英] Silverlight stop page closing before being saved

查看:45
本文介绍了Silverlight 在保存之前停止页面关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WinForms 的过去,如果您的用户在 DialogBox 中创建/编辑某些信息,很容易检测到窗口关闭,如果数据脏了,询问他们是否要保存.

In the old days for WinForms, if your user was creating/editing some information in a DialogBox, it was easy to detect the Window closing and if the data was dirty, ask if they wanted to save.

我的问题是,您如何在 Silverlight 中处理这种情况,其中似乎一切都在 UserControls 中完成,而 UserControls 没有明显的方式知道页面何时关闭,即切换到 Silverlight 应用程序中的另一个页面只会打开一个不同的 UserControl 不检查以前的 UserControl 需要保存.

My question is, how do you approach this scenario in Silverlight where everything seems to be done in UserControls, which have no obvious way of knowing when the page is closing, ie switching to another page within the Silverlight app would simply open a different UserControl without checking the previous UserControl needed saving.

必须有一些标准的方法来实现这一点吗?

There must be some standard way of achieving this?

推荐答案

如果你需要询问用户是否保存的问题,那么你需要在浏览器中处理这个onbeforeunload(虽然不是标准事件,但正式支持 Silverlight 的浏览器支持它).可以设置一些 javascript 在 onbeforeunload 触发时回调到您的应用程序.

If you need to ask the user a question about whether to save or not then you will need to handle this in the browser the onbeforeunload (whilst not a standard event it is supported by those browsers on which Silverlight is officially supported). It may be possible to set up a little javascript to call back into your application when onbeforeunload fires.

也就是说,我不喜欢你确定,你想放弃你刚刚完成的所有工作吗"类型的问题.我当然不想丢了,先存起来,只要以后有需要可以撤消我就开心了".

That said I'm not a fan of the "Are you sure, you want to lose all that work you've just done" type of question. "Of course I don't want lose it, save it already, as long as I can undo it later if necessary I'm happy".

这篇关于Silverlight 在保存之前停止页面关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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