Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SearchPane.GetForCurrentView | getForCurrentView method

Applies to Windows only

Retrieves an instance of the search pane from which users can search within the app.

Syntax


var searchPane = Windows.ApplicationModel.Search.SearchPane.getForCurrentView();

Parameters

This method has no parameters.

Return value

Type: SearchPane

An instance of the search pane, which provides a consistent, touch-friendly search box and optional search suggestions for searching within the current application.

Remarks

Note  An app can't use both the search box (Windows.UI.Xaml.Controls.SearchBox for Windows Store apps using C++, C#, or Visual Basic, WinJS.UI.SearchBox for Windows Store apps using JavaScript) and the SearchPane. Using both the search box and the search pane in the same app causes the app to throw an exception with this message: "Cannot create instance of type 'Windows.UI.Xaml.Controls.SearchBox.'"

Examples

For C#/C++/VB: This example demonstrates how to ensure that your app can respond to user queries at any time by overriding OnWindowCreated in App.xaml.cs/App.xaml.cpp/App.xaml.vb to access the SearchPane object and register handlers for SearchPane events (like QuerySubmitted).


protected override void OnWindowCreated(WindowCreatedEventArgs args)
{
    // At window creation time, access the SearchPane object and register SearchPane events
    // (like QuerySubmitted, SuggestionsRequested, and ResultSuggestionChosen) so that the app
    // can respond to the user's search queries at any time.

    // Get search pane
    Windows.ApplicationModel.Search.SearchPane searchPane = SearchSearchPane.GetForCurrentView();
    
    // Register event handlers for SearchPane events

    // Register QuerySubmitted event handler
    searchPane.QuerySubmitted += new TypedEventHandler<SearchPane, SearchPaneQuerySubmittedEventArgs>(OnQuerySubmitted);
    
    // Register a SuggestionsRequested if your app displays its own suggestions in the search pane (like from a web service)
    // Register a ResultSuggestionChosen if your app uses result suggestions in the search pane    
}

For JavaScript: This example demonstrates how to access the searchPane to register a querysubmitted event handler.

Note  To ensure that your app can respond to user queries at any time, make sure your searchPane event handlers are registered in your app's global scope.



// Register event handler for QuerySubmitted
Windows.ApplicationModel.Search.SearchPane.getForCurrentView().onquerysubmitted = function (eventObject) {
    // Respond to query and perform search
};

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.Search
Windows::ApplicationModel::Search [C++]

Metadata

Windows.winmd

See also

SearchPane class

 

 

Show:
© 2014 Microsoft