Reputation: 2967
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.
Any tips?
Thanks!
Upvotes: 3
Views: 2167
Reputation: 14202
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();
More info on the WinRT asynchronous programming pattern can be found on MSDN.
Upvotes: 6