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.

• In its event handler, the app determines whether it has anything to share in its current state. If it<br />

does, it populates the Windows.ApplicationModel.DataTransfer.DataPackage provided in the<br />

event. (This can vary with the selection or lack thereof; if the user needs to make a selection for<br />

share to work, the app can display a message to that effect.)<br />

• Based on the data formats in the package, Windows—that is, the share broker who manages the<br />

contract—determines the share target apps to display to the user. The user can also control<br />

which apps are shown through Change PC Settings > Share.<br />

• When the user picks a target, the associated app is activated and receives the data package to<br />

process however it wants.<br />

FIGURE 12-1 Processing the Share contract as initiated by the user’s selection of the Share charm.<br />

This whole process provides a very convenient shortcut for users to take something they love in one<br />

app and get it into another app with a simple edge gesture and target app selection. It’s like a<br />

semantically rich clipboard in which you don’t have to figure out how to get connected to other apps.<br />

What’s very cool about the Share contract, in other words, is that the source doesn’t have to care what<br />

happens to the data—its only role is to provide whatever data is appropriate for sharing at the moment<br />

the user invokes the Share charm (if, in fact, there is appropriate data—sometimes there isn’t). This<br />

liberates source apps from the burden of having to predict, anticipate, or second-guess what users<br />

might want to do with the data. Perhaps they want to email it, share it via social networking, drop it into<br />

a content management app…who knows?<br />

Well, only the user knows, so what the share broker does with that data is let the user decide! Given<br />

the data package from the source, the broker matches the formats in that package to target apps that<br />

have indicated support for those formats in their manifests. The broker then displays that list to the user.<br />

That list can contain apps, for one, but also something called a quicklink (a Windows.ApplicationModel.-<br />

DataTransfer.ShareTarget.Quicklink object, to be precise), which is serviced by some app but is much<br />

494

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

Saved successfully!

Ooh no, something went wrong!