I use SearchBox to list some items retrieved from the server. The server is called in an asynchronous method.
I get an exception. An exception of type "System.InvalidOperationException" was thrown. WinRT information: method was called at unexpected time.
My xaml
<SearchBox Name="SearchBox"
Style="{StaticResource AccountSearchBoxStyle}"
Grid.Row="1"
Margin="120,0,0,0"
HorizontalAlignment="Left"
SuggestionsRequested="SearchBox_SuggestionsRequested"
SearchHistoryEnabled="False" > </SearchBox>
My code
private async void SearchBox_SuggestionsRequested(SearchBox sender,
SearchBoxSuggestionsRequestedEventArgs args){
if (string.IsNullOrEmpty(args.QueryText))
{
return;
}
var collection = args.Request.SearchSuggestionCollection;
if(oldquery != args.QueryText)
{
var listOfBanks = await addFIPageViewModel.GetBanksOnQuery();
foreach (Institution insti in listOfBanks)
{
collection.AppendQuerySuggestion(insti.name);
}
oldquery = args.QueryText;
}}
source
share