W8WIL #5: Bringing the Awesome in Search

In this, the 5th, installment of Windows 8, What I’ve learned, I’m going to share a single line of code that can make your search-enabled Windows Store app absolutely awesome!

Start by enabling Search

For starters, if you haven’t enabled the Search contract in your app, you probably should. Unless your app is a game or other kind of app that has no content to search, implementing the Search contract will enable your users to more easily find content in your app, whether it’s running or not, and allow them to do so via a consistent UI that’s part of Windows 8 itself:


Adding “type to search”

Now, it’s great to implement Search, but with a single line of code, you can allow your app to behave just like the Windows 8 Start screen, so that when a user starts typing, the Search charm is automatically invoked, and the user can simply hit the Enter key (or tap the search icon next to the search box) to search for the term they typed. Here’s the line of code, which you can place in the initialization for the page where you’d like it to apply (I put mine in the ready function of groupedItems.js in the Grid App template):

Windows.ApplicationModel.Search.SearchPane.getForCurrentView().showOnKeyboardInput = true;

That’s it…really! This is an almost zero-effort addition to your app that will add a nice bit of polished functionality and make your users’ lives easier. If I hit Enter when typing as in the previous screenshot, I get the following results:


Pretty cool, if you ask me. And if I’m an end-user, I don’t even have to remember the shortcut for search. Just type and go!

Tips on “type to search”

  • Enable type to search on your main page or pages containing content that the user is likely to search
  • Enable type to search on search result pages, in case the user wants to search again
  • Avoid enabling type to search on pages with input fields, as type to search will direct keyboard input to the Search charm rather than the page’s input fields


And here are some helpful guidelines for implementing Search in your app, which is where I originally found this helpful tidbit.

Generation App

Do you have a great idea, and want help turning it into a great app? Then you should register for Generation App. The Generation App program includes a 4-week process to get you from idea to app, including links to all the right documentation, tips, videos, and more. You can also access 1:1 phone support to talk with a Microsoft engineer about technical or design questions you may have. So sign up today!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.