Search code examples
xamlsearchwindows-8windows-rt

Removing search suggestions from searchpane in windows store app


I want to show only the search suggestions from my in-app search and not the suggestions which are present by default in the SearchPane of windows store app. THere are apps in the search pane which are present by default and I dont want to show them with my app search results.


Solution

  • In your search page just add:

    Register Event:

    SearchPane.GetForCurrentView().SuggestionsRequested += OnSuggestionsRequested;
    

    Handle suggestion request event:

    void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args)
    {
        string query = args.QueryText.ToLower();
        string[] terms = { "salt", "pepper", "water", "egg", "vinegar", "flour", "rice", "sugar", "oil" };
    
        foreach(var term in terms)
        {
            if (term.StartsWith(query))
                args.Request.SearchSuggestionCollection.AppendQuerySuggestion(term);
        }
    }