Xamarin Forms绑定到列表中的List吗?

时间:2016-04-27 12:22:04

标签: xamarin xamarin.forms

我正在尝试将ListView控件绑定到List中的List。我有它显示主要列表?但不能显示里面的列表。我真的坚持这一点,我有一种感觉,我会以错误的方式去做。

我有以下XAML:

<ListView x:Name="list"
        ItemsSource="{Binding col}"
        IsGroupingEnabled="True"
        GroupDisplayBinding="{Binding Key}">
<ListView.GroupHeaderTemplate>
  <DataTemplate>
    <ViewCell Height="30">
      <StackLayout VerticalOptions="FillAndExpand"
                   Padding="5"
                   BackgroundColor="#239A23">
        <Label Text="{Binding Key}" TextColor="White" VerticalOptions="Center"/>
      </StackLayout>
    </ViewCell>
  </DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
  <DataTemplate>
    <TextCell Text="{Binding ProjectName}" Detail="Hello"/>
  </DataTemplate>
</ListView.ItemTemplate>

使用以下ViewModel:

public ProjectsViewModel()
    {
        using(var db = DependencyService.Get<IDatabase>().GetDBConnection())
        {
            var results = db.GetAllWithChildren<Gang>().ToList();
            var sorted = results
                .OrderBy(gang => gang.WorkDate)
                .GroupBy(gang => gang.WorkDate)
                .Select(Group => new Grouping<DateTime, Gang>(Group.Key, Group));
            col = new ObservableCollection<Grouping<DateTime, Gang>>(sorted);
        }
    }

模型就像这样:

public class Gang
{ ....
    public List<GangMember> GangMembers {get; set;}
}

0 个答案:

没有答案