Hello
I am tryng to suggest places to my user as they type to a textbox.
I already declared a Listox in order to show the results, but I do not know how to call the api as the user type, and show the listbox with places.
App https://github.com/eduardoagr/RsidentsManager
For example: like how Bingsugget places as you type
By thhe way I am using Bing Api to do this and MVVM
UI
<TextBox
materialDesign:HintAssist.Hint="Address"
materialDesign:HintAssist.IsFloating="True" />
<ListBox Visibility='Collapsed' />
Services - Api Method
public static async Task<List<string>> CallApi(string query) {
using (var client = new HttpClient()) {
var list = new List<string>();
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
var content = await client.GetAsync(requestUri: $"{baseUri}?{QUERY_PARAMETER}{query}{MKT_PARAMETER}");
if (content.IsSuccessStatusCode) {
string jsonContent = await content.Content.ReadAsStringAsync();
SearchSuggestion response = JsonConvert.DeserializeObject<SearchSuggestion>(jsonContent);
if (response.Query != null) {
list.Add(response.Query);
}
}
return list;
}
}
VM
public class PrpertiesWindowViewModel : BaseViewModel {
public List<int> Rooms { get; set; }
public PrpertiesWindowViewModel() {
Rooms = new List<int>();
FillList();
}
private void FillList() {
for (int i = 1; i < 5000; i++) {
Rooms.Add(i);
}
}
}
}