0

我有这样的模型

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>

但是如何绑定本身是 List 的 ExamSubjects 属性?

4

1 回答 1

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>

有关更多详细信息,请遵循

于 2016-09-09T13:36:00.503 回答