我试图做一些事情,我认为将是非常简单的失落,但.. 我创建了一个支点申请和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 >
我想以填充该列表框中的东西..并创建了一个ObservableCollection
mainpage.xaml.cs,我想我可以指向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集合,但没有在列表框中。
我做错了什么?我认为这应该很简单。
现在速度很快! :-)但是在partyList对象(Listbox)上没有这样的方法? – user975369
你使用的是什么类型的listBox?如果您浏览到partyList的定义并让我知道。 –