O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing Contracts

Early in the chapter, we discussed interaction with charms on the start bar. Those interactions are handled in your app by implementing the appropriate contracts. There are several contracts your app can implement, with Search and Share being the most important.

Saying that a contract is “implemented” sounds like implementing an abstract interface, but in fact many contracts are implemented merely by taking two steps:

1. Declare that the app will work with the control by changing the Package.appmanifest item in the project.
2. Handling an event at the application level to find out when the user selected the charm associated with the contract.

Let's step through a very simple case for working with the Search charm. This is by no means a full search implementation; it just shows the minimum code to detect when a Search has been requested and then do something in the UI.

First, start a new app with the Blank App template, and name it SearchContractExample.

To declare support for the Search contract, open the Package.appmanifest item in the project and go to the Declarations tab. It has a drop-down for the various declarations, and the Search contract is in the list. Figure 13.23 shows the Declarations page, with the list of available declarations dropped down.

Figure 13.23 The Package.appmanifest Declarations page, showing the drop-down of declarations. The Search contract declaration is selected in the drop-down.

To declare support for a Search contract, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required