SearchTextBox and inconsistent behaviour with SuggestSource

358
0
05-05-2022 04:08 AM
Vidar
by
Occasional Contributor II

I have an ESRI control, SearchTextBox on my dockpane which I intend to show a suggested list of known authors in autocomplete dropdown that appears underneath the control - this is inbuilt functionality. You have to populate the SuggestionSource with an ObservableCollection of type objects.

In my case I am passing a list of strings (after the user types at least 2 letters). I assign my list of strings to ObservableCollection<object> AuthorList which is bound in XAML:

 

 <controls:SearchTextBox 
    x:Name="AuthorTextBox" SuggestionListMax="15"
    SuggestionSource="{Binding AuthorList}" ShowMagnifier="False" 
    InfoText="Author" SearchMode="Manual" 
    TextChanged="AuthorTextBox_OnTextChanged">
</controls:SearchTextBox>

 

As you can see this works to some extent (see below) - but it does not populate on every key press - it is very intermittent - even if you wait 1 minute! between each key press - sometimes nothing populates, then you can press delete and lose focus and click back, then add some letters and it populates, but it is very erratic in behaviour and this is very frustrating for me.

Vidar_0-1651748149656.png

So I am typing "Jones" - and I debug and I can clearly see that the list has been cleared and it is about to accept 15 new entries,

Vidar_1-1651748378553.png

 

however this seems to be ignored. When I go back to the application the control looks like this:

 

Vidar_2-1651748597840.png

 

Here is my code on the text changed event - it is retrieving a list of 15 authors in sub second speed, it is very fast.

private async void AuthorTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
{
	if (AuthorTextBox.Text.Length > 2)
	{
		try
		{
			UriBuilder uriBuilder = new UriBuilder
			{
				Scheme = "https",
				Host = "localhost",
				Path = "service/AuthorBasic/1",
				Port = 7269,
				Query = $"name={AuthorTextBox.Text}"
			};

			var response = await CitationSearchVM.Client.GetAsync(uriBuilder.Uri);

			if (response.IsSuccessStatusCode == false)
			{
				Log.Error("FAIL: " + response.StatusCode);
			}
			else
			{
				string jsonText = await response.Content.ReadAsStringAsync();
				AuthorBasicResponse authorResponse = JsonConvert.DeserializeObject<AuthorBasicResponse>(jsonText);
				Module1.CitationSearchVM.AuthorList.Clear();

				Module1.CitationSearchVM.AuthorList.AddRange(authorResponse.Authors);
			}
		}
		catch (Exception ex)
		{
			Log.Error(ex);
		}
	}
}

I don't know whether its some race condition or something I must be subtlety doing wrong.

If anyone can help it would be much appreciated.

 

 

 

 

 

 

 

 

 

 

Tags (2)
0 Kudos
0 Replies