If you have been paying attention to any of the Windows 8/Metro stuff that has come out sense BUILD you may have noticed that with Windows 8/Metro application developers can now easily light up their applications by enabling their apps to hook into the system search mechanism. This post (and subsequent ones) will walk though how to enable this in your application.
Window 8 has enabled developers to hook into various system ‘Contracts’ such as Search, Sharing and Settings. Contracts are like agreements between Windows and one or more Metro style apps, called contract participants, to support some kind of user interaction. There is a contract for each type of interaction, like playing music from an application to a connected stereo, and the contract specifies the types of capabilities the participant has.
Enabling Search
This post will focus on how to setup your Metro application for simple integration. By ‘simple’ I mean we will only enable the hooks in order to allow people to search content inside of our application from the Windows 8 Search Charm. Future posts will talk (see above) about how to enable deeper hooks into the search Contract.
Step 1: Declaring your application is Searchable
- Find the Package.appxmanifest file in your UI solution
- Double click on this file, this should bring up Manifest UI screen
- Click on the Declarations Tab
- Choose ‘Search’ from the Available Declarations drop down, hit Add
- You should now see a screen as below

Step 2: Hooking into the Search Activated Events
- Open up the App.xaml.cs file
- Add an override for the OnSearchActivated method
- Inside your OnSearchActivated method you can get the current query string from args.QueryText
Step 3: Handling and doing something useful with the Search Query
- You should now have the args.QueryText value.
- Open some search form and push in the query text into either a ViewModel search method or code behind method (please use the VM not the code behind)
- Do something useful w/ the query string….
If you follow the above steps (step 1 and 2 are the important ones) you will enable basic searching abilities inside your Windows 8 Metro application.
Till next time,
Posted
09-25-2011 7:11 AM
by
Derik Whittaker