C# Datacontext Windows 8应用程序
这是我第一次创建Windows8应用程序,因为我必须为学校的项目做准备。我对xaml中的数据绑定等并不陌生,但在创建W8应用程序时会有所不同,因为它不像我通常做的那样工作 XAML代码:(我的数据模板在中) 运行时,我会在调试窗口中获取所有数据和日期。C# Datacontext Windows 8应用程序,c#,xaml,C#,Xaml,这是我第一次创建Windows8应用程序,因为我必须为学校的项目做准备。我对xaml中的数据绑定等并不陌生,但在创建W8应用程序时会有所不同,因为它不像我通常做的那样工作 XAML代码:(我的数据模板在中) 运行时,我会在调试窗口中获取所有数据和日期。 运行应用程序时有一个文本块,但其中没有内容。要在ItemsControl中显示项目,需要使用IEnumerable对象设置ItemsSource属性 <ListView ItemsSource="{Binding lineups}"/>
运行应用程序时有一个文本块,但其中没有内容。要在ItemsControl中显示项目,需要使用IEnumerable对象设置ItemsSource属性
<ListView ItemsSource="{Binding lineups}"/>
您需要设置
ItemsSource
,而不是ItemsControl的DataContext:
<ItemsControl ItemTemplate="{StaticResource test}" ItemsSource="{Binding ListLineup}">
我没有像你那样幸运;我总是不得不做Control.ItemsSource=myEnumerable代码>(或在某些情况下.DataContext)谢谢,我确实在DataContext之前使用了itemsSource,但这也不起作用。My datatemplate位于MyDataContext
属性中,用于定义对象系统将在其中查找所需属性。另外,如果不设置DataContext
,它将从父元素获取DataContext
。在VisualStudio中查看调试输出,所有绑定错误都记录在那里。我的调试中没有错误。这是我的datacontext现在datacontext=“{Binding ListLineup,RelativeSource={RelativeSource Self}}}”和Itemssource是列表,尽管我不明白为什么必须将列表作为Itemssource?不幸的是,仍然不起作用
public async void GetAllNeededLists()
{
ListLineup = await LineUp.GetLineUp();
foreach (var lu in ListLineup)
{
Debug.WriteLine(lu.Date);
}
}
<ListView ItemsSource="{Binding lineups}"/>
<ListView.ItemTemplate>
<DataTemplate>...</DataTemplate>
</ListView.ItemTemplate>
<ItemsControl ItemTemplate="{StaticResource test}" ItemsSource="{Binding ListLineup}">