Derik Whittaker

Syndication

News


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

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 episode we will look at how we can enable real time search integration.  What do I mean by Real Time Search integration?  When building a Metro Application you have the ability to not only handle unprovoked search queries from the operating system, but you also have the ability to hook into the search screen (seen below) but you also have the ability listen to various events that the Search Panel offers.  By enabling your application to listen for these events you can do a few things like get the search query text as it is being typed.  We can also handle the search request, this is different than the prior post because in this case your application is currently running.

image

How do we enable Real Time Search Integration?

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
    SearchPane.GetForCurrentView()
  3. Store the instance of this pane as a global variable/property

Step 2: Hookup your applications to the correct events

  1. Using the Pane instance you gathered in step 1, wire up the following 2 events
    1. QueryChanged
    2. QuerySubmitted

Step 3: Handle the events and do something special

Now that we have the events wired up it is now up to you to do something special in the handlers.  In my code base I don’t actually handle the QuerySubmitted event because I am doing filtering on the fly as the user is typing it.

If you want to get the current querystring value both events provide the following args.QueryText.  The Query Text will give you the value of the search as it is being typed.

As you can see hooking your metro application to work with the search in real time is pretty  much cake.  However, even though it is easy it will light up your application and provide a very rich user experience for your users.

Till next time,


Posted 09-25-2011 5:28 PM by Derik Whittaker

[Advertisement]

Comments

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

Thank you for submitting this cool story - Trackback from DotNetShoutout

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)