首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将两个Listview合并为一个带有标头的Listview

将两个Listview合并为一个带有标头的Listview
EN

Stack Overflow用户
提问于 2018-12-27 17:08:26
回答 1查看 42关注 0票数 0

如何在xamarin.forms中组合两个带有头部的列表视图。到目前为止,我已经知道我可以使用组Listview来实现this.But,我不确定如何实现通过静态数据实现它的源代码的this.All,但在我的例子中,Listview项是动态的。

它是如何通过静态数据实现的。

代码语言:javascript
复制
List<GroupListModel> Groups = new List<GroupListModel>
            {
                new GroupListModel("list1","list1")
                {
                 new UserModel
                 {
                     FirstName = "list 1-1",
                     LastName= "12",
                 },
                },
                new GroupListModel("list2","list2")
                {
                    new UserModel
                    {
                        FirstName = "list2-1",
                        LastName= "1",
                    },
                    new UserModel
                    {
                        FirstName = "list2-2",
                        LastName= "2",
                    },
                    new UserModel
                    {
                        FirstName = "list2-3",
                        LastName= "3",
                    },
                    new UserModel
                    {
                        FirstName = "list 2-4",
                        LastName= "4",
                    },
                },
            };

            All = Groups;

这是我的分组列表模型,

代码语言:javascript
复制
public class GroupListModel:List<UserModel>
{
    public string Title { get; set; }
    public string ShortName { get; set; }
    public string Subtitle { get; set; }
    public GroupListModel(string title, string shortName)
    {
        Title = title;
        ShortName = shortName;
    }

    public List<UserModel> Listofusers;

    public static List<GroupListModel> All { set; get; }
},

我想要的是list1中的数据必须是动态的,即List1列表项目应该包含从服务器调用返回的数据列表。

我想要这样的东西。I want a listview like this

有没有人能帮我。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-12-27 19:55:23

IsGroupingEnabled设置为true

代码语言:javascript
复制
<ListView ItemsSource="{Binding GroupList}"  IsGroupingEnabled="True">
    <ListView.GroupHeaderTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding Title}" />
            </ViewCell>
        </DataTemplate>
    </ListView.GroupHeaderTemplate>

    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal" Spacing="5">
                   <Label Text="{Binding FirstName}" />
                   <Label Text="{Binding LastName}" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53942450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档