Mar 252014
 March 25, 2014  Posted by at 9:01 am C# & F#, WinRT  Add comments

More on Search in WInRT: Search history
A few weeks back I asked on Twitter if you preferred to have search history on or off when doing searches in an application. The majority said off, some said a limited history and some preferred to have a button allowing them to toggle history on or off.

More on Search in Windows Store Apps:

SearchBox MVVM implementation with event arguments

Dirty fix: Search in Windows 8.1 does not work

Implementing Search in Windows Store Apps 8.1 – screenshot guide

Advanced searching with Windows 8 Search

User friendly SearchBox in Windows Store Apps: separators, suggestions and result items

How do we work with search history in Windows Store Apps?

SearchHistory is enabled by default but can be disabled with the SearchHistoryEnabled property, and you can even grab a SearchHistoryContext if you want different contexes depending on where the user does the search.

To access the global object that manages search, be that panel or SearchBox control, you can use the SearchSuggestionManager, found under: Windows.ApplicationModel.Search.Core.SearchSuggestionManager


Two methods might be of interest, ClearHistory and AddToHistory. The two do exatcly what you would think. It might be just me being tired, but I couldn’t figure out a better way to limit the search history items shown besides creating a limited queue adding search items to them as the user did the search, and clearing the list before appending the queue items.

It’s 5:20 AM so it might not be the best or brightest idea I’ve had, let me know if there are other ways. Anyway, there is a manager object, and methods to clear or add to the search history. Use them wisely.

Oh, and let’s not forget SetLocalContentSuggestionSettings, which:

Specifies whether suggestions based on local files are added automatically to the Suggestions collection, and defines the criteria that Windows uses to locate and filter these suggestions.

Basically you can provide suggestions based on local files, and you can pass in an Advanced Query Filter to grab exactly what you want, the folder used, properties to match etc. Quite neat.

[sourcecode language=”csharp”]

// searchbox or pane => they use the same manager

var searchManager = new Windows.ApplicationModel.Search.Core.SearchSuggestionManager();

// clear history


// add to history

searchManager.AddToHistory("Cute kittens");

// Adding from limited queue

foreach (var historyItem in _searchHistory)





 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



What is 12 + 11 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)