简体   繁体   English

Xamarin 表单列表视图 - 数据模板到列

[英]Xamarin Forms List view - Data template into columns

How could I achieve two columns using only a Xamarin Forms listview?如何仅使用 Xamarin Forms 列表视图实现两列? Can someone share an example?有人可以分享一个例子吗? I'm trying to avoid using DLToolkit or any other plugin.我试图避免使用 DLToolkit 或任何其他插件。

在此处输入图片说明

Since you specified only using the ListView, multiple columns have been implemented using custom templates, even some custom renderers.由于您仅使用 ListView 进行了指定,因此已使用自定义模板(甚至一些自定义渲染器)实现了多个列。 Links to many, many different examples can be found here:可以在此处找到许多不同示例的链接:

Xamarin Forms Forums Xamarin 表单论坛

I would, however, suggest that the work it'll take to create your own implementation of the Listview isn't worth it when there are already solutions that come out-of-box with Xamarin.Forms, CollectionView like @Jason said is one easy solution.但是,我会建议,当已经有 Xamarin.Forms 开箱即用的解决方案时,创建自己的 Listview 实现所需的工作是不值得的,@Jason 所说的 CollectionView 就是其中之一简单的解决方案。

 <CollectionView x:Name="clv" ItemsUpdatingScrollMode="KeepItemsInView" >ItemsSource="{Binding ActiveItems}” Margin="20" Header="{Binding .}" > <CollectionView.HeaderTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="25"></RowDefinition> </Grid.RowDefinitions> <Label Text="Select " HorizontalTextAlignment="Start" LineBreakMode="WordWrap" FontAttributes="Bold" FontSize="22" InputTransparent="True" /> </Grid> </DataTemplate> </CollectionView.HeaderTemplate> <CollectionView.ItemsLayout> <GridItemsLayout Orientation="Vertical" HorizontalItemSpacing="20" Span="2" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid > <Grid.RowDefinitions> <RowDefinition Height="150" /> <RowDefinition Height="2*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="25" /> </Grid.ColumnDefinitions> <Image Grid.Row="0" Grid.ColumnSpan="2" Source="Icon" Aspect="AspectFill"/> <Label Text="{Binding alterName }" FontSize="18" FontAttributes="Bold" LineBreakMode="WordWrap" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM