How to: Create a Custom Search Panel
- 2 minutes to read
This example demonstrates how to create a custom search panel.
- Build a custom search panel. In this example, the panel contains two text edits (for the Location and Keywords) and the Search button.
- To implement searching, create a InformationLayer object to the MapControl.Layers collection and assign a BingSearchDataProvider object to the InformationLayer.DataProvider property.
- To search a location, the BingSearchDataProvider.Search method should be called. In this example, this method is called in the Search button click event handler.
Note
If you run the application, and see a window with the following error message: ”The specified Bing Maps key is invalid. To create a developer account, refer to https://www.microsoft.com/en-us/maps/create-a-bing-maps-key”, refer to the following tutorial: How to: Get a Bing Maps Key.
<dxm:InformationLayer.DataProvider>
<dxm:BingSearchDataProvider x:Name="searchProvider"
ShowSearchPanel="False"
BingKey="{Binding Source={StaticResource bingKey}}"
SearchCompleted="searchProvider_SearchCompleted">
<dxm:BingSearchDataProvider.SearchOptions>
<dxm:BingSearchOptions x:Name="options"
AutocorrectQuery="{Binding ElementName=cbAutocorrect, Path=IsChecked}"
DistanceUnit="{Binding ElementName=lbDistanceUnits, Path=SelectedValue}"
ResultsCount="{Binding ElementName=tbCount, Path=Value}">
</dxm:BingSearchOptions>
</dxm:BingSearchDataProvider.SearchOptions>
</dxm:BingSearchDataProvider>
</dxm:InformationLayer.DataProvider>
<Button Grid.Row="2" Margin="4" Click="bSearch_Click">Search</Button>
See Also