HTML and CSS Reference
In-Depth Information
Handling requests for data
You open the
todolist.js
file and add the following code at the bottom of the
TodoList.init
method:
// Initialization of Share source contract
var clipboard = Windows.ApplicationModel.DataTransfer.DataTransferManager.
getForCurrentView();
clipboard.addEventListener("datarequested", function (e) {
// Get the information to share
var currentTask = TodoList.getTaskFromUI();
// Share information as plain text
TodoList.shareDataAsPlainText(e, currentTask);
// Share information as HTML
TodoList.shareDataAsHtml(e, currentTask);
});
The
clipboard
variable references the data transfer manager object active for the current window.
Data transfer manager is the system component responsible for transferring data in and out of your
application. You use the
addEventListener
method to register a handler for the
datarequested
event.
This event is fired whenever the user brings up the Share panel and there's at least one application
ready to receive data.
Note
Windows 8 doesn't disable the Share button on the Charms bar if the current
application doesn't support the
Share source
contract. So the user can always try to share
content from within any application. However, if the
DataTransferManager
object detects
that the current application doesn't expose a handler for the
datarequested
event, a
message is shown like in Figure 9-8.
In the handler for the
datarequested
event, you collect the data to share, format the data in the
way you like and package data up in a
DataPackage
object. In the code snippet above, the data to
share is represented by the task being created. Task information is shared as plain text and HTML.
The order in which data is added to the package (plain text is added first in the previous code snippet)
is unimportant. The format shared actually depends on the settings of the receiver application.
Search WWH ::
Custom Search