Derik Whittaker



Lighting up your C# Metro apps by Enabling Search–Part 3

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

In this post we will take a look at how your application can provide context sensitive suggestions to the search panel.  Adding these suggestions can provide your imageuser the ability to not have to type the entire search term in order to perform a search.  It also provides a list of known keywords that your application can use which by default provides your user a higher level of confidence that the keyword they are searching on will return data.

How do we setup the ability to provide keywords to the Search Panel?

Step 1: Get the instance of the Current Search Pane

  1. Add a reference to the Windows.ApplicationModel.Search Namespace.
  2. Grab the instance of the pane by using the following syntax
  3. Store the instance of this pane as a global variable/property

Step 2: Hookup your applications to the correct eventyo

  1. Using the Pane instance you gathered in step 1, wire up the following event
    1. SuggestionsRequested

Step 3: Build a list of keywords to provide as suggestions

In my code base I have a repository method which will parse a list of keywords and return them as a List<string>.  One thing to pay attention to is that your string can only contain ONE WORD.  I have tried this with multiple words and it does not appear to work.  I don’t know if this is a Developer Preview limitation or if this is intended behavior but either way only put a single word per line in your search result list

Step 4: Handle the SuggestionsRequested Event callback

In the handler of your SuggestionsRequested event you need to push your list of suggestion keywords into the Requested args as follows


Once you have pushed your list of suggestions into the SearchSuggestionCollection you should now see your suggestions in the search panel when searching on your application.

Till next time,

Posted 09-26-2011 5:40 PM by Derik Whittaker
Filed under: , , , ,


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)