question

EduardoGomez-1870 avatar image
1 Vote"
EduardoGomez-1870 asked HuiLiu-MSFT commented

Populating listbox as I type

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-wpfdotnet-wpf-xaml
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@EduardoGomez-1870. Welcome Microsoft Q&A.

What does it mean to use a ListBox to display the results?

0 Votes 0 ·

1 Answer

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered

Hi,@EduardoGomez-1870. 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 to enable e-mail notifications if you want to receive the related email notification for this thread. 



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.