Windows 8 Conference Buddy–Be A Sharing Source

Everybody loves to share. (At least after they are beaten into doing so in pre-school.)

The ability to share from one application to another can be anything from useful to critical. Historically, we’ve seen a number of ways of doing this, the most enduring of which is the clipboard. Windows 8, however, introduces a system-wide sharing mechanism that is like the clipboard on steroids, and more important, which is easy to program and easy to use.

Sharing will be critical to our Conference Buddy application as we’ll want to share contacts and event information.

Architecture

The process of sharing sounds complicated, but the programmer’s role is pretty straightforward, and made even easier by the sharing target contract that we’ll talk about in the next posting.

Here’s the architecture:

One application is the source. This is the provider of information and the part we’ll implement today. The source registers with the DataTransferManager and when the user wants to share the source receives an event which it responds to by filling a DataPackage.

The (invisible, behind-the-scenes) ShareBroker filters the list of Target Apps (which we’ll build tomorrow) that can handle the types of data you are sharing. The user selects the target app of choice and that application is activated. The targret processes the data package contents and reports complete.

Implementation

Creating a Sharing source is incredibly easy. Create a new application and call it ShareSource. Give the view a simple TextBlock that says “hello.”

Turn to OnNavigatedTo. Here we create an instance of the DataTransferManager by calling GetForCurrentView, a static method on the DataTransferManager class. Once we have that, we can register for the DataRequested event handler.

That’s it! You can now run your application and when it starts, swipe to bring in the charms. Click on Search and you will be presented with a list of all the applications registered on your computer that can handle the data types you are presenting (text and html), as shown in the cropped image at the top of this posting.

Touch on Mail and notice that the Title you entered is used as the subject, and the HTML you entered is used as the body of the message.

If the target you chose only supported plain text, then the text message would have been used instead of the HTML.

About Jesse Liberty

Jesse Liberty is a Master Consultant for Falafel Software, and has three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Technical Evangelist for Telerik and for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS.