How to Set the Minimum Characters for AutoCompleteBox to filter in Windows Phone ?

The AutoCompleteBox that is part of Silverlight Toolkit for Windows Phone by default shows the suggestions when you type one character in the AutoCompleteBox .

You can change this behaviour . For example , if you want to display the Suggestions in the Autocompletebox if you type 3 characters or more , you can set the property MinimumPrefixLength to 3 .

Assume that the AutocompleteBox has the following List as ItemSource .

public List<string> GetSports()

{

List<string> Sports = new List<string>();

Sports.Add("Cricket - One Day");

Sports.Add("Cricket - Test");

Sports.Add("Tennis");

Sports.Add("Table Tennis");

Sports.Add("Hockey");

Sports.Add("Football");

return Sports;

}

If you Set the MinimumPrefixLength of the AutoCompleteBox to 3 , then you should get the the suggestion only when you type 3 or more characters as shown below

AutoCompleteBox txtbox = new AutoCompleteBox();

txtbox.MinimumPrefixLength = 3;

stack.Children.Add(txtbox);

// Data

txtbox.ItemsSource = GetSports();

If you dont want the AutocompleteBox to show the suggested words , then set the MinimumPrefixLength of AutoCompleteBox to -1 .

Leave a Reply