如何在 XAML 中为 UWP 应用程序显示来自 SQLite 的相关数据?
How can I display related data from SQLite in XAML for UWP apps?
Visual Studio 调试显示我已经成功从数据库中取出数据。我的数据库有两个 table,条款 table 包含 table 年的外键,如下所示:
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:
<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>
我如何显示一个年份,以便它包含引用它的所有术语?
我花了很长时间试图解决这个问题,如果能提供任何帮助,我将不胜感激☺
为术语列表使用另一个 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>
Visual Studio 调试显示我已经成功从数据库中取出数据。我的数据库有两个 table,条款 table 包含 table 年的外键,如下所示:
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:
<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>
我如何显示一个年份,以便它包含引用它的所有术语?
我花了很长时间试图解决这个问题,如果能提供任何帮助,我将不胜感激☺
为术语列表使用另一个 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>