Click here to Skip to main content
15,798,200 members
Articles / Desktop Programming / Win32

A Study of Windows 8 'Contracts' - Why, What and How?

Rate me:
Please Sign up or sign in to vote.
4.53/5 (9 votes)
21 Feb 2012CPOL7 min read 37.9K   10   9
This article is a study of Windows 8 'Contracts' - why they are introduced? what they really are? and how they can be created?


Windows 8 is the complete revamp of the existing Windows operating system as said by the Microsoft developer team. Microsoft took every care to enhance the features of existing operating systems in order to implement a fluid, fast and consistent operating system all over different hardware architectures and fully utilize the advantages of cloud to personalize usage.

To list a few of Windows 8 features, we have the following:

  1. Support for both x86 PCs and ARM tablets
  2. Windows To Go, a new feature in Windows 8 that enables enterprise administrators to create USB drives containing complete, managed Windows images that users can use to boot and run Windows on any Windows 7 or Windows 8 capable computer.
  3. Windows Store, to compete with Apple, Windows has confirmed the introduction of a Windows Store, similar to Mac App Store, which allows users to browse through Windows applications, while developers can publish their Metro-style apps on Windows 8 devices.
  4. Fluid, fast and best user interface. Speaking about the UI, Windows 8 certainly has got a mind blowing interactive UI, which has been extensively redesigned to a “Metro-style” design, which shows the most important information to you, embodies simplicity, and gives you full control over it. The UI is designed to provide a fluid and intuitive interaction and navigation with (multi-)touch, or a mouse and keyboard.
  5. Contracts
  6. etc.

This list is not exhaustive and in this article, we concentrate on the fifth feature “Contracts” that are introduced in Windows 8 that enables the applications (developed by distinct unknown developers) to talk to each other. To state it simply, contracts here are developer clipboard, a universal clipboard of apps and services that ties back to Internet Explorer 10.

Note: Before going in depth about contracts, if you are new to Windows 8 environment, I would recommend you have a good understanding of Windows 8 Metro style UI and what are the new features and responsibilities it’s going to provide for a developer.

Why “Contracts”?

The answer to this question is quite simple; “because users often come across information they’re excited to share with someone or utilize in another app”. In the Metro interface of Windows 8, where only one application has the screen at a time, this will be a boon to developers and users alike, working to increase the usefulness in situations where one app owning the screen at a time is necessary.

So What Are “Contracts” All About?

Steven Sinofsky, the President of the Windows Division, in his keynote of Build events, mentioned contracts as being a key element of the Windows 8 development platform.

As per his words, “Applications should be able to work together without knowing anything about each other”. He cited an example using a few of the different “charms,” or main icons, in Windows 8. (The five charms are Devices, Settings, Share, Search and Start.) Applications and services — including the coming Windows Live app/service hybrids — that implement contracts will be able to make use of a data package from Internet Explorer 10, enabling users to remain inside of an app from which they are sharing, searching, etc. In Windows 8, there are share contracts, search contracts and “picker” contracts.

Sinofsky also hinted that the closest analogy to a “contract” is a clipboard. (As per history, the former Microsoft Chief Software Architect Ray Ozzie has a concept of “universal clipboard” — dating back to 2006. Ozzie’s universal clipboard, which he released under a Creative Commons license, was focused on connecting Web sites and desktop applications using a combination of RSS feeds, other XML data and the desktop clipboard. It’s not sure whether Windows 8 team relied on Ozzie’s vision and code, if at all.)

In Windows 8, an application can expose features through a contract. The contract details what the offered feature needs to work and what it will produce. Think of it like the input/output paradigm in Apple's Automator; but able to be tapped into by any application on the system, not just through a single central authority like Automator. More importantly, these features can be tapped into seamlessly, the user never having to leave the current application but still being able to tap into the full functionality present on their device.

A Little Technicality of “Contracts”

The “currency” (here, currency refers to the trading items between source and target apps) in a Share contract is known as a DataPackage. The data can be captured and shared in a number of different formats, including text, URI, HTML, images and other extensible formats.

Source apps in the Share scenario can include news, magazines, media, games, social networking data, notes captured via a note-taking program and data stored in the cloud. Target categories on which Microsoft is expecting developers to focus include social networking, communication, entertainment, print services, “device connected” scenarios, note-taking and cloud storage.

Here, Windows does the heavy lifting so that apps don’t need to know much about each other in order to create amazing experiences!

Contracts implementation consists of three parties:

  1. Source apps: This is the source of data.
  2. Share Broker: This is a mediating layer that talks to source and target apps.
  3. Target apps: These are the recipients of the data and shows them in their UI context.

Note: In ideal cases, every application should be a perfect source and best target. Hence, at times, we refer source apps as ‘share source apps’ and target apps as ‘share target apps’.

Hence, “Share target” refers to applications, which acts as targets as well as share the information. Being a Share target will increase usage of your app or service and keeps your service fresh with content that matters to users.

The four steps involved in sharing from source to target are depicted in terms of pictures as follows:

Step 1

The source application has to register itself with datatransfer manager. Now share broker (which is a mediator to both source and target apps), on the user request, will send an event to the source app on behalf of the target app. The source application responds to the event by starting to fill the datapackage.


Step 2

The source app completes filling the datapackage and completes all its async operations before responding to share broker with datapackage. The share broker does an additional step of filtering the data received from source app and models it as links as per user’s criteria.


Step 3

Now user can see search results on the screen from the source app. At this point, the user can click the desired result he wants to explore. So once he clicks on the links, the share broker notifies the target app with the data and the target app prepares its user interface to show the result it received on its user interface.


Step 4

This is the final step, where in the target app shows the result made up of source app’s data and reports a completed notification to share broker.


More about 'datapackage'

The data package can contain any data in it. Source apps should include as many representations of the data as possible to maximize the set of target apps.

Pseudo code that represents the datapackage construction is as follows:


Notes to Consider for a Source App

Overusage of this contract should be avoided. For example “find” in a worksheet should not be coupled with “Search” charm. The subsets of functionality that a source app should satisfy are:

  1. Listen for and handle a Share event to participate
  2. Content should be shared in two ways:
    1. Implicit – user selects Share without making a selection
    2. Explicit – user selects content in an app and then selects Share
  3. Build data package for best results

The most anticipated source apps categories are News, Magazine, Media, Games, Social networking, Note taking, Cloud storage, etc.

Pseudo code for setting up a share source app:


Notes to Consider for a Share Target App

The subsets of functionalities that a share target app should satisfy are:

  1. Register as a Share target and specify the formats you accept
  2. Build your app UI to look best as part of the Share experience
    1. Selection of people or places to Share within your app
    2. Quick, lightweight experience
  3. Use the DataPackage to tailor the user experience
  4. Report completion
  5. Return a Quicklink

The anticipate share target apps are Social networking, Communication, Entertainment, Print service, Device connected, Note taking, Cloud storage, etc.

Pseudo code for setting up a share target app:



The above article is not the exact implementation of contracts since the concept itself is new, but will provide an overview of what are contracts and how we are going to deal with them in the coming days. The pseudo code is not the part of exact implementation, but are snapshots of the picture we are going to see when we develop applications in the metro-world.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Junior) Thomson Reuters
India India
Currently, I am Software Engineer in ThomsonReuters. I am a man who believes in a fact that -"Technology is best available now-a-days but what matter is "How you use it?" and "What you solved using it?" ....." My site, my work and everything about me demonstrates this basic idea. I do what I love and I love what I do.....
U can find all about me @ Smile | :)

Comments and Discussions

GeneralMy vote of 5 Pin
Krekkon17-Oct-13 9:03
Krekkon17-Oct-13 9:03 
QuestionNice article. Pin
akcode31-Jan-13 7:26
akcode31-Jan-13 7:26 
GeneralMy vote of 5 Pin
Kanasz Robert28-Sep-12 8:12
professionalKanasz Robert28-Sep-12 8:12 
GeneralMy vote of 5 Pin
Sentenryu27-Feb-12 9:53
Sentenryu27-Feb-12 9:53 
GeneralRe: My vote of 5 Pin
Krishnachytanya Ayyagari28-Feb-12 0:44
Krishnachytanya Ayyagari28-Feb-12 0:44 
Questionnice Pin
BillW3324-Feb-12 5:33
professionalBillW3324-Feb-12 5:33 
AnswerRe: nice Pin
Krishnachytanya Ayyagari24-Feb-12 10:47
Krishnachytanya Ayyagari24-Feb-12 10:47 
GeneralMy vote of 4 Pin
johannesnestler21-Feb-12 5:17
johannesnestler21-Feb-12 5:17 
GeneralRe: My vote of 4 Pin
Krishnachytanya Ayyagari21-Feb-12 5:33
Krishnachytanya Ayyagari21-Feb-12 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.