[英]Best Way to add footer view in Xamarin forms list view?
I noticed that Xamarin forms ListView doesn't have a method similar to addFooterView in Android. 我注意到Xamarin表单ListView没有类似于Android中的addFooterView的方法。
I want to add a submit button at the bottom the list. 我想在列表底部添加一个提交按钮。
Whats the best way to achieve this? 什么是实现这一目标的最佳方法?
You could write your own custom renderer for Xamarin.Forms ListView , and add in the ability to expose the addFooterView in Android perhaps? 您可以为Xamarin.Forms ListView编写自己的自定义渲染器 ,并添加在Android中公开addFooterView的功能 ?
This would be the simplest way of extending the support for this on the Android platform specifically. 特别是在Android平台上扩展对此功能的支持的最简单方法。
Update 1 更新1
To achieve something that is applicable across all platforms you could customize the cell appearance based on the data it represents. 为了实现适用于所有平台的功能,您可以根据其表示的数据来自定义单元外观。
In Xamarin.Forms you are able to write your own custom Cell implementations that can be used in a ListView or TableView . 在Xamarin.Forms中,您可以编写自己的自定义Cell实现,该实现可以在ListView或TableView中使用 。
Therefore to achieve the ' Load More ' effect at the bottom of the ListView , you could add an extra Model item into your collection, with some flag indicating that it is this type of display to be shown, rather than the normal Cell representation of a real Model item. 因此,要在ListView的底部实现“ 加载更多 ”效果,您可以在集合中添加一个额外的Model项,并带有一些标志,指示将要显示的是这种类型的显示,而不是普通的Cell表示。真实模型项目。
Evaluating this flag, you would be able to determine whether you should show the ' Load More ' custom view or not. 评估此标志,您将能够确定是否应显示“ 加载更多 ”自定义视图。
When you are going to add more data, naturally you would remove this item, prior to adding new items, and then also add this ' special case ' Model item afterwards. 当您要添加更多数据时,您自然会在添加新项目之前 删除该项目,然后再添加此“ 特殊情况 ” 模型项目。
you can do it the way Pete described or in a non ListView related way. 您可以按照Pete所述的方式或与ListView不相关的方式进行。 If i had to implement a fixed footer i would put a ListView and a StackLayout into a grid with two rows.
如果我必须实现固定的页脚,则会将ListView和StackLayout放入具有两行的网格中。 The ListView's row has a *asterisk height and the StackLayout an Auto sized height.
ListView的行具有*星号高度,而StackLayout具有Auto大小的高度。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListView Grid.Row="0">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout Grid.Row="1">
<Label Text="Your fixed footer"/>
</StackLayout>
</Grid>
Update If you need a customizable cell on the bottom of the ListView then you can simply use the Footer property of the ListView. 更新如果您需要在ListView的底部有一个可自定义的单元格,则只需使用ListView的Footer属性即可。
<ListView ItemsSource="{Binding Items}" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="Some Titles"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout>
<Label Text="Footer of the ListView"/>
</StackLayout>
</ListView.Footer>
</ListView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.