Adding more to your Windows 8 app with less code: Share Contracts

The Share Contract in Windows 8 is a great way to let other people’s code improve your app

I love the Share Contact in Windows 8. I love it as a developer because it allows applications other people are writing to enhance my application. I also love it as a geek because it is such a great example of the power of interfaces and contracts in your code.

I am working on an app for my sister’s photography company, Unposed. the first version is fairly straightforward: the app provides a portfolio of her pictures, information on her studio and the ability to request an photo shoot. The metro look and feel is going to make her pictures shine! The plan is, in version two, to update the application with the ability for her clients to login and view their pictures in the application.  Of course when you are looking at pictures from a photo shoot and trying to decide what to order you may want to email a photo to granny and grandpa, or post a particularly great shot on facebook, google plus, or twitter, or whatever other social media comes along next week. By implementing the share source contract in my code, I’ll be able to share the images selected by the user with all of the above!

First let me introduce you to the concept of Share for those who haven’t seen it yet. I’ve opened the Photo application in Windows 8 and selected a picture from my laptop taken at a Microsoft event where we had a photo booth. We took this awesome picture of me and my co-workers (Fred Harper, Mitch Barnett, Alex Yakobovich, and Ruth Morton) and I want to share it with my friends. I bring up the Charms bar and select the Share charm.


Because this application has implemented the Share Source contract, when I select the share charm, I am presented with a list of applications who are willing to accept this shared content. Right now I am running the consumer preview (this weekend I will install the release preview which is available now!) and I don’t have too many apps to choose from yet, just the Email app and a Share Target Sample app which I will explain shortly.



When I select mail, it launches the mail application and creates a new email with the photo I selected as content! Any Windows 8 Metro application that has implemented the ShareTarget contract will appear in that list when I choose share. So anyone who writes a Facebook app, a twitter app, or an email app will be implementing the Share target contract and will write the code that figures out how to handle/post/send the content that is shared from my application or other applications.

This means as a developer I don’t have to try and guess if my user prefers Facebook or LinkedIn and I don’t have to learn how to call all the different APIs and I don’t have to worry about adding new code when a new social media app takes off. If I implement the Share source contract in my code I can simply say when a user is in this application they may choose to share content. Then whatever app the user happens to have installed on their laptop with the share target contract will pop up and they can use it to share their favourite photo with their friends. great functionality for my users with minimum work required by me! Sweet!

TIP! Since Windows 8 is only at the release preview stage you may not have a lot of apps installed which you can use to test that your Share Source contract is implemented correctly. Download the Share Target Sample App. This app gives you a preview of what you are sharing so you can be confident that you have correctly implemented Share Source in your application.

Visit and you will find Guidelines for sharing content in Metro apps, and a Quick start for sharing Content (with either JavaScript and HTML or with VB/C#/C++ and XAML

If you are working on a Windows 8 app, don’t forget to sign up for an App Excellence Lab so you can be first to the store in Canada, and ask yourself does my app have any content users my want to share with others? If so implement the Share source contract, maximum wow for minimum effort!

Comments (0)

Skip to main content