如何在Xamarin表单中更改listview中最后一行的样式

如何在Xamarin表单中更改listview中最后一行的样式,listview,xamarin.forms,portable-class-library,Listview,Xamarin.forms,Portable Class Library,对于要在列表视图中显示的给定列表,如何针对最后一行编辑其样式? 使用页脚 <ListView.Footer> <StackLayout Orientation="Horizontal"> <Label Text="Footer" TextColor="Gray" BackgroundColor="Blue" /> </StackLayout> </ListView.Footer> 2.在主页中,为型号列表设置值

对于要在列表视图中显示的给定列表,如何针对最后一行编辑其样式?

  • 使用页脚

    <ListView.Footer>
       <StackLayout Orientation="Horizontal">
          <Label Text="Footer" TextColor="Gray" BackgroundColor="Blue" />
       </StackLayout>
    </ListView.Footer>
    
    2.在
    主页中
    ,为型号列表设置值

     var people = new List<Person> {
            new Person ("Kath", new DateTime (1985, 11, 20), "France" ,false),
            new Person ("Steve", new DateTime (1975, 1, 15), "USA",false),
            new Person ("Lucas", new DateTime (1988, 2, 5), "Germany",false),
            new Person ("John", new DateTime (1976, 2, 20), "USA",false),
            new Person ("Tariq", new DateTime (1987, 1, 10), "UK",false),
            new Person ("Jane", new DateTime (1982, 8, 30), "USA",false),
            new Person ("Tom", new DateTime (1977, 3, 10), "UK",true)
        };
    
结果:

编辑: 如果您从json数据中获取列表,那么您应该浏览该列表,并在步骤2中手动将isLastRow添加到对象中。 像这样:

int index = 0;
foreach(Person person in list){
     person.isLastRow = (index == list.Count-1);
     index ++;
}

您可以根据需要使用DataTemplateSelector。但您需要为标识模型中的最后一行(ListView项绑定模型)再添加一个属性,如布尔IsLast。尝试将页脚用于listview@MikeDarwish你还有什么问题吗?@PavanVParekh我正在从服务器获取Json数据,我无法将IsLast添加到object@MikeDarwish我不能使用页脚,因为我在列表上使用了ContextAction,因此页脚将无法访问ContextAction实际上我是从Json数据获取列表的,因此我无法将IsLastRow添加到objectBrilliant,谢谢
protected override DataTemplate OnSelectTemplate (object item, BindableObject container)
{
    return ((Person)item).IsLastRow ? ValidTemplate : InvalidTemplate;
}
int index = 0;
foreach(Person person in list){
     person.isLastRow = (index == list.Count-1);
     index ++;
}