Reputation: 730
Visual Studio debugging shows that I have successfully retrieved the data from the database. My database has two tables, with the Terms table containing a foreign key from the Years table, as seen below:
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>
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 βΊπ
Upvotes: 1
Views: 432
Reputation: 734
Use another GridView control (or ListView) for list of Terms:
<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>
Upvotes: 0