简体   繁体   English

在Xamarin表单列表视图中添加页脚视图的最佳方法?

[英]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实现,该实现可以在ListViewTableView中使用

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.

相关问题 水平列表视图添加页脚视图 - Horizontal List View add Footer View 在Xamarin.Forms中显示包含许多其他视图的视图的最佳方法 - Best way to display view that includes many other views in Xamarin.Forms 带有滚动的列表视图从 UI 中推出页脚 Xamarin android - List view with scroll pushes out of the UI the footer Xamarin android 根据视图创建动态页脚的最佳方法,android - Best way to create dynamic footer depending on the view, android Xamarin Forms - 添加 Android AutoCompleteTextView 作为本机可绑定视图 - Xamarin Forms - Add Android AutoCompleteTextView as native bindable view 在Xamarin Forms Custom Renderer中将Mapbox添加到Android视图 - Add Mapbox to Android View in Xamarin Forms Custom Renderer 将可扩展列表视图作为页眉或页脚视图添加到抽屉布局内的另一个可扩展列表视图 - Add expandable list view as a header or footer view to another expandable list view inside a drawer layout 列表视图在Xamarin.forms中不包含“ ItemsSource”的定义? - List view does not contain a definition for 'ItemsSource' in Xamarin.forms? 在Android中将动画添加到自定义视图的最佳方法 - Best way to add animation to custom view in Android 在Android列表视图中获取位置的最佳方法 - Best way to get a location in an android list view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM