Derik Whittaker

Syndication

News


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

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

  1. Find the Package.appxmanifest file in your UI solution
  2. Double click on this file, this should bring up Manifest UI screen
  3. Click on the Declarations Tab
  4. Choose ‘Search’ from the Available Declarations drop down, hit Add
  5. You should now see a screen as below
    image

Step 2: Hooking into the Search Activated Events

  1. Open up the App.xaml.cs file
  2. Add an override for the OnSearchActivated method
  3. 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

  1. You should now have the args.QueryText value.
  2. 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)
  3. 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

[Advertisement]

Comments

Derik Whittaker wrote Lighting up your C# Metro apps by Enabling Search–Part 2
on 09-25-2011 6:29 PM

If you have been paying attention to any of the Windows 8/Metro stuff that has come out sense BUILD you

DotNetShoutout wrote Lighting up your C# Metro apps by Enabling Search–Part 1
on 09-26-2011 4:35 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Derik Whittaker wrote Lighting up your C# Metro apps by Enabling Search–Part 3
on 09-26-2011 6:40 PM

If you have been paying attention to any of the Windows 8/Metro stuff that has come out sense BUILD you

Jowen Mei wrote re: Lighting up your C# Metro apps by Enabling Search–Part 1
on 10-28-2011 5:03 AM

Hi Derik

Instead of step1, it's easier to just add a Search contract item to your project.

regards, Jowen

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)