Edit
After understanding your use case then what you need is use the Populating
event. This event is fired when you want to populate the drop-down with possible matches. To make this called once 2 characters or more have been typed you will also need to set MinimumPrefixLength
to 2.
Moreover, change your GetStreets
method to take a string
param containing the chars in the textbox.
// Your page Loaded event. Bind this event in your xaml.
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) {
AutoCompleteBox_Streets.MinimumPrefixLength = 2;
AutoCompleteBox_Streets.Populating += AutoComplete_Populating;
}
private async void AutoComplete_Populating(object sender, PopulatingEventArgs e) {
// e.Parameter will contain the chars in your textbox.
AutoCompleteBox_Streets.ItemsSource =
await GetStreets(HttpUtility.UrlEncode(e.Parameter));
AutoCompleteBox_Streets.PopulateComplete();
}
private async Task<List<string>> GetStreets(string chars) {
JObject jo = new JObject();
jo.Add("chars", chars);
// Rest of your method code
// ...
}
What you need is setting MinimumPrefixLength
property to 2.
Also move your bindings to the constructor and remove the TextChanged
event.
// Your constructor
public MyPage() {
InitializeComponent();
BindStreetNames();
}
private async void BindStreetNames() {
AutoCompleteBox_Streets.ItemsSource = await GetStreets();
AutoCompleteBox_Streets.MinimumPrefixLength = 2;
}
private async void AutoCompleteBox_Streets_TextChanged(object sender, RoutedEventArgs e) {
/* Remove this handler */
}