【发布时间】:2015-05-05 00:40:23
【问题描述】:
我有一个 Windows Phone 应用程序,我正在尝试将 ObservableCollection 绑定到一个列表框,以便在此刻列出字符串。但是,当我运行应用程序时,没有列出任何内容,而且我看不到哪里出错了。
XAML:
<ListBox ItemsSource="{Binding EventList}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Black" FontSize="20"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
代码隐藏:
private ObservableCollection<String> eventList = new ObservableCollection<String>();
public ObservableCollection<String> EventList
{
get { return eventList; }
}
public MainPage()
{
eventList.Add("Event One");
eventList.Add("Event Two");
eventList.Add("Event Three");
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
【问题讨论】:
标签: xaml binding listbox windows-phone