0

所以我试图将多组项目添加到 xamarin 表单中的列表视图中。它仅适用于简单的对象,例如:

todoListView.ItemsSource = new List<TodoItem> 
            {
                    new TodoItem{ TimeLeft="13:30", Location="The Room", Title="IM AN URGENT TITLE!", ImageURL="Unread.png", Unread=true, TodoText="This is some random text to illustrate a useless point." },
                    new TodoItem{ Title="IM A TITLE!", ImageURL="Unread.png", Unread=true, TodoText="This is some random text to illustrate a useless point." }
            };

但是当我添加这样的组时:

    todoListView.ItemsSource = new List<TodoListGroups>
    {
        new TodoListGroups("Test")
        {
            new TodoItem{ Title="IM A TITLE!", ImageURL="Unread.png", Unread=true, TodoText="This is some random text." }
        }
    };

我收到以下错误:“Ninterpret.interpretedObject”类型的对象与“System.Collections.Generic.List`1[Ninterpret.interpretedObject]”类型不匹配(TargetException)

My model looks like this:
using System;
using System.Collections.Generic;
using System.Text;

namespace xyz
{
    public class TodoListGroups : List<TodoItem>
    {
        public string Title { get; set; }

        public TodoListGroups(string title)
        {
            Title = title;
        }
    }
}

供参考的xaml是:

<ContentPage Icon="list.png" Title="Todos">
            <StackLayout Orientation="Vertical">
                <ListView SeparatorColor="OrangeRed" x:Name="todoListView" HasUnevenRows="True" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal" Padding="5">
                                    <Image Source="{Binding ImageURL}"></Image>
                                    <StackLayout HorizontalOptions="StartAndExpand">
                                        <Label Text="{Binding Title}"></Label>
                                        <Label Text="{Binding TodoText}" TextColor="Gray"></Label>
                                    </StackLayout>
                                    <Button Text="Done"></Button>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage>
4

0 回答 0