Populating listbox as I type

Eduardo Gomez 2,326 Reputation points
2022-06-22T22:22:05.953+00:00

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);  
        }  
    }  
}  

}

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,178 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
558 questions
1 vote

Accepted answer
  1. Hui Liu-MSFT 14,796 Reputation points Microsoft Employee
    2022-06-23T07:21:52.503+00:00

    Hi,@Eduardo Gomez . Welcome Microsoft Q&A.
    If you want to get suggestions as you type via Github from your post, you could check out the code here.

    The result:
    214188-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html


0 additional answers

Sort by: Most helpful