3

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!

Community
  • 1
  • 1
ariestav
  • 2,799
  • 4
  • 28
  • 56

1 Answers1

6

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.

Nathan Kuchta
  • 13,482
  • 2
  • 26
  • 35