23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• App is in the snapped state and is invoked as above, in which case Search will go to the Start<br />

screen.<br />

• App is suspended and is invoked as above.<br />

You should also be mindful of how you present results, taking care that the primary results are<br />

not hidden by the Search pane, which will remain visible until the user dismisses it.<br />

Sidebar: Synchronizing In-App Search with the Search Pane<br />

Some types of apps will still maintain their own in-app search UI in addition to using the search<br />

pane, or in other ways they might have some kind of search term that would be good to keep in<br />

sync with the term shown in the search pane. To do this, the app can ask the search pane for its<br />

queryText value and can attempt to set that value through the SearchPane.trySet-QueryText<br />

method. This call will fail, mind you, if the app isn’t itself visible or if the search pane is already<br />

visible or becoming visible.<br />

Providing Query Suggestions<br />

Using querysubmitted and the activation sequence in the previous section gives you the basic level of<br />

search interaction, and Windows will automatically provide a history of the user’s recent searches. Still,<br />

with just a little more work you can make the experience much richer. Because writing the code to<br />

actually perform the search, process the results, and display them beautifully is the bulk of the work with<br />

the Search contract anyway, adding support for query suggestions (this section) and result sugges-tions<br />

(next section) is a relatively small investment with a huge impact on the overall user experience.<br />

To go beyond the default search history and provide as-the-user-is-typing query suggestions, which<br />

appear to the user as shown on the left side of Figure 12-10, you have two options. Which one you use<br />

depends on what you want to suggest and the data that you’re searching.<br />

First, to provide suggestions from folders on the file system, such as the music, pictures, and videos<br />

libraries, the search pane provides a built-in implementation through its<br />

setLocalContent-SuggestionsSettings method with results like those in Figure 12-12. As shown in<br />

Scenario 4 of the sample, you first create a<br />

Windows.ApplicationModel.Search.LocalContentSuggestion-Settings object, populate its<br />

properties, and then pass that object to setLocalContent-SuggestionsSettings (js/scenario4.js):<br />

var page = WinJS.UI.Pages.define("/html/scenario4.html", {<br />

ready: function (element, options) {<br />

var localSuggestionSettings = new<br />

Windows.ApplicationModel.Search.LocalContentSuggestionSettings();<br />

localSuggestionSettings.enabled = true;<br />

localSuggestionSettings.locations.append(Windows.Storage.KnownFolders.musicLibrary);<br />

localSuggestionSettings.aqsFilter = "kind:=music";<br />

520

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!