[ACCEPTED]-Error: Items collection must be empty before using ItemsSource-windows-phone-7
Accepted answer
You want to create the list only once and 3 assign the data source only once! Therefore, create 2 the list before the loop and assign the data source 1 after the loop
// Clear the listbox.
// If you never add items with listBox1.Items.Add(item); you can drop this statement.
listBox1.Items.Clear();
// Create the list once.
List<Taskonlistbox> dataSource = new List<Taskonlistbox>();
// Loop through the tasks and add items to the list.
for (int i = 0; i < tasks.Count(); i++) {
dataSource.Add(new Taskonlistbox {Text = "Blalalalala"} );
}
// Assign the list to the `ItemsSouce` of the listbox once.
this.listBox1.ItemsSource = dataSource;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.