如何在Xamarin .forms中一个接一个地显示一个xaml文件中的两个listview? [英] How to display two listview in one xaml file one after other in Xamarin .forms?

查看:79
本文介绍了如何在Xamarin .forms中一个接一个地显示一个xaml文件中的两个listview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四个不同的列表视图,分别从四个不同的数据源获取数据.每个列表视图,我创建了一个单独的列表,使用了单独的RESTful api.我想在一个xaml页面中一个接一个地显示所有列表视图,例如在Facebook中进行通知.参考链接- Android如何在一个活动中一个接一个地显示2个列表视图. 我想在Xamarin.forms中创建

I have four different listview which is getting data from four different data source.Each listview, I have created separate which is consuming separate RESTful api.I want to display all the listview in one xaml page one after another like notification in facebook. Link for reference - Android how to display 2 listviews in one activity one after the other. I want to create in Xamarin.forms

推荐答案

不确定您需要什么,但似乎您想在单个ListView中显示至少4种不同的数据类型.可以通过DataTemplateSelector完成.

Not sure what you need, but seems like you want to display at least 4 different data types in a single ListView. It can be done with DataTemplateSelector.

可以使用DataTemplateSelector在运行时选择一个DataTemplate 基于数据绑定属性的值.这使得多个 DataTemplates应用于相同类型的对象,以便 自定义选择对象的外观.

A DataTemplateSelector can be used to choose a DataTemplate at runtime based on the value of a data-bound property. This enables multiple DataTemplates to be applied to the same type of object in order to customize the appearance of select objects.

有关示例和详细信息,请参见此处.

Examples and details are available here.

P.S .:在同一页面上具有多个ListView,尤其是其中的四个,可能表示UX气味.但是,如果您仍然希望在同一页面上具有多个ListView,则可以这样做:

P.S.: Having multiple ListViews on the same page, especially four of them, may indicate a UX smell. But, if you still want to have multiple ListView on the same page, it is doable:

<ContentPage>
   <StackLayout Orientation="Vertical">
      <ListView ItemsSource="{Bindind Source1}" />
      <ListView ItemsSource="{Bindind Source2}" />
      <ListView ItemsSource="{Bindind Source3}" />
      <ListView ItemsSource="{Bindind Source4}" />
   </StackLayout>
</ContentPage>

这篇关于如何在Xamarin .forms中一个接一个地显示一个xaml文件中的两个listview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆