I want to display a ListBox with around 10 items in it. Every time I update it by adding an item to a List
it causes a little but noticeable delay and the UI freezes for a little while. I also tried using an ObservableCollection
instead of a List
as the ItemsSource
, which didn't fix the problem.
My ListBox must update really fast, so I really need your help, please! :)
Here is some code:
public partial class MainPage : PhoneApplicationPage
{
//private List<Word> Words = new List<Word>();
ObservableCollection<Word> Words = new ObservableCollection<Word>();
// Konstruktor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ListBox1.ItemsSource = Words;
for (int j = 0; j < 10; j++)
{
Words.Add(new Word(j.ToString()));
}
}
}
public class Word
{
public String sWord { get; set; }
public Word(String word)
{
this.sWord = word;
}
}
XAML
<ListBox Name="ListBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Content="{Binding sWord}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>