Adding a search page

Warning: As of Windows 8.1 it is no longer recommended to use the search contract for in app search (see the SearchBox control instead). This feature is included in the Okra App Framework for legacy use only.

The Okra App Framework makes it easy to add a search page to your Windows Store application. Advantages of using the framework include,

Thankfully these intricacies are handled by the framework and all you need to do is to provide the desired UI and business logic.

Creating a search page

Initialize the search manager by adding the following import to your application bootstrapper,

using Okra.Search;

public class AppBootstrapper : OkraBootstrapper
{
    [Import]
    public ISearchManager SearchManager { get; set; }

    ...
}

Open the ‘Package.appxmanifest’ file for the solution. In the ‘Declarations’ tab add the ‘Search’ declaration and save changes to the ‘Package.appxmanifest’

Add a new page and view-model to the project that will be used as a search page

Add PageExport and ViewModelExport attributes naming the page SpecialPageNames.Search

[PageExport(SpecialPageNames.Search)]
public sealed partial class MySearchPage : Page
{
    ...
}

[ViewModelExport(SpecialPageNames.Search)]
public class MySearchViewModel
{
    ...
}

The view-model should also implement the Okra.Search.ISearchPage interface. This interface defines a single PerformQuery(…) method that is called every time a search is performed. Note that this may be called multiple times for a single page instance, since if the user performs subsequent searches then the page should be updated each time.

[ViewModelExport(SpecialPageNames.Search)]
public class MySearchViewModel : Okra.Search.ISearchPage
{
    ...

    public void PerformQuery(string queryText, string language)
    {
        throw new NotImplementedException();
    }
}