Here’s a sample code that i was trying for databinding the AutoCompleteBox in Windows Phone 7 .
What’s wrong with this WP7 Code ?
I was trying to bind a custom object to the AutoCompleteBox and ended up looking at the code for nearly 30 mins to figure out why the suggestion was not displaying . It was a simple fix though …
Try finding out the error in the code .
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
List<Movie> Lst = new List<Movie>();
Lst.Add(new Movie { Name = "Velayutham", Actor = "Vijay" });
Lst.Add(new Movie { Name = "Nanban", Actor = "Vijay" });
Lst.Add(new Movie { Name = "Yohan", Actor = "Vijay" });
Lst.Add(new Movie { Name = "Billa 2", Actor = "Ajith" });
Lst.Add(new Movie { Name = "Maatran", Actor = "Surya" });
autoCompleteBox1.ItemsSource = Lst;
}
}
class Movie
{
public string Name { get; set; }
public string Actor { get; set; }
}
The above code worked fine when i modified the line 21 from
class Movie
{
public string Name { get; set; }
public string Actor { get; set; }
}
to
public class Movie
{
public string Name { get; set; }
public string Actor { get; set; }
}Just a introduction of the keyword public solved the problem 🙂