我有这样的模特
public class ExamMaster
{
public int Id {get;set;}
public string Name {get;set;}
public string StartDate {get;set;}
public string EndDate {get;set;}
public List<SubjectMaster> ExamSubjects {get;set;}
}
public class SubjectMaster
{
public string Name {get;set;}
public int MaxMark {get;set;}
public int MinMark {get;set;}
public int Score {get;set;}
}
如何在xaml视图上绑定ExamMaster。我设法绑定了像这样的简单属性
<Grid>
<BoxView Color="#006793" />
<ContentView Padding="20">
<Label Text="{Binding Name}" FontAttributes="Bold" FontSize="15"/>
<Label Text="{Binding StartDate}" FontAttributes="Bold" FontSize="15"/>
But how to bind the ExamSubjects property which itself is a List??
</ContentView>
</Grid>
但是如何绑定ExamSubjects属性本身就是List ??
答案 0 :(得分:0)
这样做设置ItemsSource="{Binding ExamSubjects }"
,然后定义DataTemplate以呈现列表的属性
<ListView x:Name="listView" ItemsSource="{Binding ExamSubjects }">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Label Text="{Binding Name }" FontAttributes="Bold" />
<Label Grid.Column="1" Text="{Binding MaxMark }" />
<Label Grid.Column="2" Text="{Binding MinMark }" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
了解更多详情,请点击this