23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

You then configure the dialog through its commands, options, defaultCommandIndex (the command<br />

tied to the Enter key), and cancelCommandIndex (the command tied to the ESC key).<br />

The options come from the Windows.UI.Popups.MessageDialogOptions enumeration where there are<br />

only two members: none (the default, for no special behavior) and acceptUserInputAfterDelay (which<br />

causes the message dialog to ignore user input for a short time to prevent possible clickjacking; this<br />

exists primarily for Internet browsers loading arbitrary web content and isn’t typically needed for most<br />

apps).<br />

The commands property then contains up to three Windows.UI.Popups.UICommand objects, the same<br />

ones used in context menus. Each command again contains an id, a label, and an invoked property to<br />

which you assign the handler for the command. Note that the defaultCommandIndex and<br />

cancelCommandIndex properties work on the indices of the commands array, not the id properties of those<br />

commands. Also, if you don’t add any commands of your own, the message dialog will default to a<br />

single Close command.<br />

Finally, once the dialog is configured, you display it with a call to its showAsync method. Like the<br />

context menu, the result is the selected UICommand object that’s given to the completed handler you<br />

provide to the promise’s done method. Typically, you don’t need to obtain that result because the<br />

selected command will have triggered its associated invoked handler where you process those<br />

commands.<br />

Note If the Search, Share, Devices, or Settings charm is invoked while a message dialog is active, or if<br />

an app is activated to service a contract, a message dialog will be dismissed without any command<br />

being selected. The completed handler for showAsync will be called, however, with the result set to the<br />

default command. Be aware of his if you’re using the completed handler to process such commands.<br />

The Message dialog sample—one of the simplest samples in the whole Windows<br />

SDK!—demonstrates various uses of this API. Scenario 1 displays a message dialog with a title and two<br />

command buttons, setting the second command (index 1) as the default. This appears as follows:<br />

Scenario 2 shows the default Close command with a message and no title:<br />

304

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!