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!
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:
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!
And here are some helpful guidelines for implementing Search in your app, which is where I originally found this helpful tidbit.
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!
I work for Microsoft, but the views expressed on this weblog are mine and do not necessarily reflect the views of my employer.
All postings are provided "AS IS" with no warranties, and confer no rights.
Unless otherwise noted, all code provided in this blog is copyright © Microsoft Corporation, and licensed under the Microsoft Limited Public License (Ms-LPL). All rights reserved.