Back to Devexpress

BingSearchDataProvider.SearchCompleted Event

wpf-devexpress-dot-xpf-dot-map-dot-bingsearchdataprovider.md

latest9.0 KB
Original Source

BingSearchDataProvider.SearchCompleted Event

Occurs when a search operation has been completed.

Namespace : DevExpress.Xpf.Map

Assembly : DevExpress.Xpf.Map.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public event BingSearchCompletedEventHandler SearchCompleted
vb
Public Event SearchCompleted As BingSearchCompletedEventHandler

Event Data

The SearchCompleted event's data class is BingSearchCompletedEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelledGets a value indicating whether an asynchronous operation has been canceled. Inherited from AsyncCompletedEventArgs.
ErrorGets a value indicating which error occurred during an asynchronous operation. Inherited from AsyncCompletedEventArgs.
RequestResultReturns the result of the search request. Inherited from SearchCompletedEventArgs.
UserStateGets the unique identifier for the asynchronous task. Inherited from AsyncCompletedEventArgs.

The event data class exposes the following methods:

MethodDescription
RaiseExceptionIfNecessary()Raises a user-supplied exception if an asynchronous operation failed. Inherited from AsyncCompletedEventArgs.

Example

View Example

vb
Private Sub searchProvider_SearchCompleted(ByVal sender As Object, ByVal e As BingSearchCompletedEventArgs)
    If e.Cancelled Then
        Return
    End If
    If e.RequestResult.ResultCode <> RequestResultCode.Success Then
        Return
    End If

    Dim sb As New StringBuilder()

    Dim requestResult As SearchRequestResult = e.RequestResult
    sb.Append(String.Format("Result Code: {0}" & vbLf, requestResult.ResultCode))
    If String.IsNullOrEmpty(requestResult.FaultReason) Then
        sb.Append(String.Format("Fault Reason: (none)" & vbLf, requestResult.FaultReason))
    Else
        sb.Append(String.Format("Fault Reason: {0}" & vbLf, requestResult.FaultReason))
    End If
    sb.Append(String.Format("Search Location: {0}" & vbLf, requestResult.Keyword))
    sb.Append(String.Format("Estimated Matches: {0}" & vbLf, requestResult.EstimatedMatches))
    sb.Append(String.Format("SearchResults:" & vbLf & "{0}", ProcessLocationList(requestResult.SearchResults)))

    tbSearchResult.Text = sb.ToString()

End Sub

Private Function ProcessLocationList(ByVal results As List(Of LocationInformation)) As String
    If results Is Nothing Then
        Return ""
    End If

    Dim sb As New StringBuilder()
    For i As Integer = 0 To results.Count - 1
        sb.Append(String.Format("{0}) {1}", i + 1, ProcessLocationInformation(results(i))))
    Next i
    Return sb.ToString()
End Function
Private Function ProcessLocationInformation(ByVal info As LocationInformation) As String
    If info Is Nothing Then
        Return ""
    End If

    Dim sb As New StringBuilder()

    sb.Append(String.Format("{0}" & vbLf, info.DisplayName))
    sb.Append(String.Format(vbTab & "Adress: {0}" & vbLf, info.Address))
    sb.Append(String.Format(vbTab & "Location: {0}" & vbLf, info.Location))
    Return sb.ToString()
End Function
csharp
private void searchProvider_SearchCompleted(object sender, BingSearchCompletedEventArgs e) {
    if (e.Cancelled) return;
    if (e.RequestResult.ResultCode != RequestResultCode.Success) return;

    StringBuilder sb = new StringBuilder();

    SearchRequestResult requestResult = e.RequestResult;
    sb.Append(String.Format("Result Code: {0}\n", requestResult.ResultCode));
    if (String.IsNullOrEmpty(requestResult.FaultReason))
        sb.Append(String.Format("Fault Reason: (none)\n", requestResult.FaultReason));
    else
        sb.Append(String.Format("Fault Reason: {0}\n", requestResult.FaultReason));
    sb.Append(String.Format("Search Location: {0}\n", requestResult.Keyword));
    sb.Append(String.Format("Estimated Matches: {0}\n", requestResult.EstimatedMatches));
    sb.Append(String.Format("SearchResults:\n{0}", ProcessLocationList(requestResult.SearchResults)));

    tbSearchResult.Text = sb.ToString();

}

string ProcessLocationList(List<LocationInformation> results) {
    if (results == null) return "";

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < results.Count; i++) {
        sb.Append(String.Format("{0}) {1}", i + 1, ProcessLocationInformation(results[i])));
    }
    return sb.ToString();
}
string ProcessLocationInformation(LocationInformation info) {
    if (info == null) return "";

    StringBuilder sb = new StringBuilder();

    sb.Append(String.Format("{0}\n", info.DisplayName));
    sb.Append(String.Format("\tAdress: {0}\n", info.Address));
    sb.Append(String.Format("\tLocation: {0}\n", info.Location));
    return sb.ToString();
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SearchCompleted event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-map-process-search-with-a-custom-search-panel/CS/MapControl_SearchPanel/MainWindow.xaml#L38

xml
BingKey="{Binding Source={StaticResource bingKey}}"
                        SearchCompleted="searchProvider_SearchCompleted">
<dxm:BingSearchDataProvider.SearchOptions>

wpf-map-search-with-azure-map-search-service/CS/DXMapExample/MainWindow.xaml#L32

xml
BingKey="{Binding Source={StaticResource bingMapsKey}}"
SearchCompleted="OnSearchCompleted"
LayerItemsGenerating="OnLayerItemsGenerating" />

wpf-map-search-with-azure-map-search-service/CS/DXMapExample/obj/Debug/net8.0-windows/MainWindow.g.cs#L135

csharp
#line 32 "..\..\..\MainWindow.xaml"
this.searchDataProvider.SearchCompleted += new DevExpress.Xpf.Map.BingSearchCompletedEventHandler(this.OnSearchCompleted);

wpf-map-search-with-azure-map-search-service/VB/DXMapExample/obj.NetFX/x86/Debug/MainWindow.g.vb#L132

vb
#ExternalSource("..\..\..\MainWindow.xaml",32)
AddHandler Me.searchDataProvider.SearchCompleted, New DevExpress.Xpf.Map.BingSearchCompletedEventHandler(AddressOf Me.OnSearchCompleted)

See Also

BingSearchDataProvider Class

BingSearchDataProvider Members

DevExpress.Xpf.Map Namespace