简体   繁体   English

我想在列表视图中创建标题,并在UWP应用程序的每个列表视图下添加项目。 我应该怎么做?

[英]I want to make headers in a listview and add items under each listview in a UWP app. How should I do this?

I am making an app that tracks what a person eats. 我正在制作一个跟踪人的饮食的应用程序。 I want to have a listview that tracks all the food eaten during the day and lists it under what meal (breakfast, lunch, dinner, and snack) that the user ate it during. 我想拥有一个列表视图,该列表视图跟踪白天所有吃过的食物,并在用户进食期间将其列出为哪一餐(早餐,午餐,晚餐和小吃)。

I understand how to add the item to the list. 我了解如何将商品添加到列表中。 The only problem is I don't know how to add headers like the ones shown in the XAML Gallery, and I don't know how to add items under a specific header. 唯一的问题是我不知道如何添加标题(如XAML库中所示),而且我也不知道如何在特定标题下添加项目。 I've had some difficulty finding tutorials that explain how to do this and would like some input as to where I should look. 我在查找说明如何执行此操作的教程时遇到了一些困难,并且希望获得一些有关我应该去哪里看的信息。

I've looked at these tutorials ( tutorial 1 , tutorial 2 ) but they are somewhat confusing and I'm honestly not sure if what they show is what I'm trying to do. 我看过这些教程(第1 教程,第2教程 ),但是它们有些令人困惑,而且老实说我不确定它们显示的内容是否是我想做的。

What is the name of what I'm trying to do, and how should I go about it? 我要做什么的名字是什么,我应该怎么做? Any tutorials for what it is I'm trying to accomplish would be very helpful. 我想要完成的任何教程都将非常有帮助。

From your description, It seems you want to implement a grouping list. 从您的描述来看,您似乎想要实现一个分组列表。 The recommended way is to use CollectionViewSource, which is very detailed in the tutorials you showed. 推荐的方法是使用CollectionViewSource,它在您显示的教程中非常详细。 You can create a class that includes time (breakfast...), food name, etc., then group them by time. 您可以创建一个包含时间(早餐...),食物名称等的类,然后按时间对其进行分组。 For more information about collectionViewSource, you can refer to this document . 有关collectionViewSource的更多信息,您可以参考本文档 If you are still confused, can you describe in more detail where is the problem? 如果您仍然感到困惑,能否详细描述问题出在哪里?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM