Search code examples
c#win-universal-appuwpsearch-box

SearchBox doesn't fire QuerySubmitted one phone when clicking search icon(UWP 10)


I have a SearchBox that works fine on desktop. When clicking on icon the QuerySubmitted event is fired.

However on phone this is not the case. With the KeyUp event i can get the enter from the keyboard UI but that doesn't help me with the issue of the icon not working.

<SearchBox PlaceholderText="" QuerySubmitted="SearchBox_QuerySubmitted" QueryChanged="SearchBox_QueryChanged">        
</SearchBox>

Code behind

    private void SearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)
    {
        Debug.WriteLine("SearchBox_QuerySubmitted");
    }

    private void SearchBox_QueryChanged(SearchBox sender, SearchBoxQueryChangedEventArgs args)
    {
        Debug.WriteLine("SearchBox_QueryChanged");
    }

Is this a bug or is this intended? Is there a work around?


Solution

  • For UWP you should use AutoSuggestBox:

    To use an AutoSuggestBox, you need to respond to 3 user actions.

    •Text changed - When the user enters text, update the suggestion list.

    •Suggestion chosen - When the user chooses a suggestion in the suggestion list, update the text box.

    •Query submitted - When the user submits a query, show the query results.

    Query submitted will be raised properly on phone. I just tested it.

    More info here : https://msdn.microsoft.com/en-gb/library/windows/apps/windows.ui.xaml.controls.autosuggestbox.aspx