[英]How can I display related data from SQLite in XAML for UWP apps?
Visual Studio debugging shows that I have successfully retrieved the data from the database. Visual Studio调试显示我已经成功从数据库中检索了数据。 My database has two tables, with the Terms table containing a foreign key from the Years table, as seen below:
我的数据库有两个表,术语表包含Years表中的外键,如下所示:
public class Term
{
[Key]
public int TermId { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int YearId { get; set; }
public Year Year { get; set; }
}
public class Year
{
[Key]
public int YearId { get; set; }
public string YearName { get; set; }
public string School { get; set; }
public string Grade { get; set; }
public List<Term> Terms { get; set; }
}
XAML: XAML:
<GridView ItemsSource="{Binding Source={StaticResource YearDisplay}}">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<TextBlock Text="{Binding YearId}" />
<TextBlock Text="{Binding YearName}" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
How can I display a Year so that it contains all the Terms which reference it? 如何显示年份,使其包含所有引用该年份的条款?
I've spent ages trying to figure this out, and I would really appreciate it if any help was given ☺🙏 我花了很长时间试图解决这个问题,如果能给予任何帮助,我将非常感谢appreciate
Use another GridView control (or ListView) for list of Terms: 使用另一个GridView控件(或ListView)获取术语列表:
<GridView ItemsSource="{Binding Source={StaticResource YearDisplay}}">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<TextBlock Text="{Binding YearId}" />
<TextBlock Text="{Binding YearName}" />
<GridView ItemsSource="{Binding Terms}">
<GridView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
<!-- ..... -->
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.