【发布时间】:2011-10-02 12:39:12
【问题描述】:
我正在尝试做一些我认为非常简单的事情,但是.. 我创建了一个数据透视应用程序并在 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 >
我想在该列表框中填写一些内容.. 并在 mainpage.xaml.cs 中创建了一个 ObservableCollection 并认为我可以将 ItemsSource 指向它,但没有任何显示列表。
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);
}
我得到消息框,我可以看到数据已到达 oblItems 集合,但列表框中没有任何内容。
我做错了什么?我认为这应该很简单。
【问题讨论】:
标签: windows-phone-7