【发布时间】:2021-06-12 22:54:20
【问题描述】:
我正在使用 ListView 组件,我想设置在 ListView 中使用 Header 的类别。
我拥有的内容是今天、明天和后天发生的事件的列表
我将如何将其添加到列表中
到目前为止我的代码如下
<ListView>
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Event 1 - Today</x:String>
<x:String>Event 2 - Today</x:String>
<x:String>Event 3 - Today</x:String>
<x:String>Event 4 - Today</x:String>
<x:String>Event 1 - Tomorrow</x:String>
<x:String>Event 2 - Tomorrow</x:String>
<x:String>Event 3 - Tomorrow</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.Header>
<Label Text="Today"/>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding}" Style="{StaticResource listViewRacecourse}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我只是不知道如何在数组中获取两个值,然后使用 ListView 标头将它们分成两组。
这只是一个 POC,所以我没有包含所有内容的数据库,因此不使用 API 或连接到数据库。
【问题讨论】:
-
如何使用数组?我看不到示例?
-
你需要在代码中构建一些模拟数据,而不是在 XAML 中
-
该死的,我希望它能够在没有它的情况下逃脱。
-
这需要 5 分钟
标签: xaml xamarin.forms