How do we add new items to a ListBox control in a Windows Metro style application at run-time?
I come from WinForms, so as you could imagine, I'm pretty confused right now.
I have the following:
public class NoteView
{
public string Title { get; set; }
public string b { get; set; }
public string c { get; set; }
}
and then:
List<NoteView> notes = new List<NoteView>();
protected void Button1_Click(object sender, RoutedEventArgs e)
{
notes.Add(new NoteView {
a = "text one",
b = "whatevs",
c = "yawns"
});
NotesList.ItemsSource = notes;
}
Which is useless. It does nothing. Also, there is nothing in the Output window. No errors, no exceptions; nothing.
So, then I tried directly adding to the ListBox:
NotesList.Items.Add("whatever!");
Again, nothing happened. So then I tried adding UpdateLayout(); but that didn't help either.
Anybody know what's up with that?
How do we add new items to a XAML ListBox?
Update:
<ListBox Name="NotesList" Background="WhiteSmoke">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title, Mode=TwoWay}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>