I am trying to do something which I thought would be really simple, but.. I have created a pivot application and inserted a listbox in MainPage.xaml
< ListBox x:Name = "partyList" Margin = "0,0,-12,0" >
< ListBox.ItemTemplate >
< DataTemplate >
< StackPanel Orientation = "Horizontal" Margin = "0,0,0,17" >
< StackPanel Width = "311" >
< TextBlock Text = "{Binding throwLocation}"
TextWrapping = "Wrap"
Style = "{StaticResource PhoneTextExtraLargeStyle}" />
< TextBlock Text = "{Binding throwText}"
TextWrapping = "Wrap"
Margin = "12,-6,12,0"
Style = "{StaticResource PhoneTextSubtleStyle}" />
</ StackPanel >
</ StackPanel >
</ DataTemplate >
</ ListBox.ItemTemplate >
</ ListBox >
I want to fill something in that listbox.. and have created an ObservableCollection
in mainpage.xaml.cs and figured I could just point ItemsSource
to that, but nothing shows up in the list.
public class ListItems
{
public string throwText;
public string throwLocation;
}
List<ListItems> listItems = new List<ListItems>();
public ObservableCollection<ListItems> oblItems =
new ObservableCollection<ListItems>();
// Load data for the ViewModel Items
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ListItems li = new ListItems();
//li.thumb = new BitmapImage();
li.throwLocation = "Denmark. Åbenrå";
li.throwText = "Throw text";
oblItems.Add(li);
partyList.DataContext = oblItems; // Don't know if this makes any sense?
partyList.ItemsSource = oblItems;
MessageBox.Show(oblItems[0].throwLocation);
}
I get the messagebox and I can see that the data has reached the oblItems collection, but nothing in the listbox.
What I am doing wrong? I thought this should be quite simple.