Auto complete text box problem
-
Hello, Im using the
System.Windows.Controls.AutoCompleteBox
Here is my XAML code:
And here is my code behind the XAML:
public partial class MainWindow : Window
{
private List myList;public List MyList { get { return myList; } } public MainWindow() { InitializeComponent(); myList = new List { "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar" }; //autocompleteBox.ItemsSource = myList; } }
When i ran this code the auto complete text box doesn't auto completes. But when i uncomment this line:
//autocompleteBox.ItemsSource = myList;
And removed this one:
ItemsSource="{Binding MyList}"
From the XAML, the auto complete text box works fine. What i'm missing? Thanks
-
Hello, Im using the
System.Windows.Controls.AutoCompleteBox
Here is my XAML code:
And here is my code behind the XAML:
public partial class MainWindow : Window
{
private List myList;public List MyList { get { return myList; } } public MainWindow() { InitializeComponent(); myList = new List { "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar" }; //autocompleteBox.ItemsSource = myList; } }
When i ran this code the auto complete text box doesn't auto completes. But when i uncomment this line:
//autocompleteBox.ItemsSource = myList;
And removed this one:
ItemsSource="{Binding MyList}"
From the XAML, the auto complete text box works fine. What i'm missing? Thanks
You don't appear to be setting the DataContext[^] anywhere. In the constructor, after you've created the list, try adding:
DataContext = this;
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer