Home > C#, WinRT > How to automatically open the Search pane when typing in a Windows Store app

How to automatically open the Search pane when typing in a Windows Store app

29/04/2013

If you type something while you are in the Start screen of Windows 8, the Search pane will automatically open, with the search text box containing the pressed character. We can obtain the same behavior in our Windows Store apps. We just need to set the ShowOnKeyboardInput of the SearchPage object to true:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Windows.ApplicationModel.Search.SearchPane.GetForCurrentView()
        .ShowOnKeyboardInput = true;
}

In this way, all keystrokes are automatically routed to Search pane, so the current view behaves similar to Start screen. However, this happens even if input controls like TextBox have focus: in a such situation, because all pressed characters will be sent to Search pane, the TextBox will remain empty.

So, it’s up to us to enable or disable the ShowOnKeyboardInput property according to the content of the page (fortunately, we can change it every time we need).

Categories: C#, WinRT
%d bloggers like this: