且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Xamarin .forms中一个接一个地显示一个xaml文件中的两个listview?

更新时间:2023-02-01 20:44:12

不确定您需要什么,但似乎您想在单个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>