如何使用 WinJS 以编程方式关闭 Win8 应用程序中的 MessageDialog? [英] How to programmatically close a MessageDialog in Win8 app using WinJS?

查看:25
本文介绍了如何使用 WinJS 以编程方式关闭 Win8 应用程序中的 MessageDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是一个类似的问题,关于如何以编程方式关闭Win8 应用程序中的 MessageDialog,但问题的作者使用的是 C#.我很好奇如何用 WinJS 解决这个问题.有没有办法使用 WinJS 以编程方式取消 MessageDialog 而无需访问对话框本身内的 CommanUI 对象?我不能简单地调用与附加的 CommandUI 按钮关联的处理程序,因为在某些情况下,我不知道哪个按钮索引具有该功能.

Here is a similar question to mine regarding how to programmatically close a MessageDialog in a Win8 app, but the author of the question is using C#. I'm curious about how to solve the issue with WinJS. Is there any way to cancel a MessageDialog programmatically with WinJS without have access to the CommanUI objects within the dialog itself? I cannot simply invoke the handler associated with an appended CommandUI button since, in some cases, I wouldn't know which button index has that functionality.

有什么建议吗?

谢谢!

推荐答案

MessageDialog.showAsync 返回一个 IAsyncOperation 对象并继承自 IAsyncInfo.IAsyncInfo 界面包括一个cancel 方法一般取消异步操作.在消息对话框的情况下,如果对话框仍然存在,则在异步操作上调用取消将关闭对话框.

MessageDialog.showAsync returns an IAsyncOperation<IUICommand> object and inherits from IAsyncInfo. The IAsyncInfo interface includes a cancel method which generically cancels asynchronous operations. In the case of the message dialog, calling cancel on the async operation will dismiss the dialog if it is still present.

var asyncOperation = messageDialog.showAsync();
asyncOperation.cancel();

可以在 MSDN 上找到有关 WinRT 异步编程模式的更多信息.

More info on the WinRT asynchronous programming pattern can be found on MSDN.

这篇关于如何使用 WinJS 以编程方式关闭 Win8 应用程序中的 MessageDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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