Listview Xamarin形成自定义单元格仅显示第一行
我是Xamarin表单的新手,我想创建一个对司机有用的应用程序。我正在尝试创建内部有多个堆栈布局的自定义单元格。但在listview中,仅显示自定义单元格的第一行。这是我的自定义单元格代码:Listview Xamarin形成自定义单元格仅显示第一行,listview,xamarin,xamarin.forms,custom-cell,Listview,Xamarin,Xamarin.forms,Custom Cell,我是Xamarin表单的新手,我想创建一个对司机有用的应用程序。我正在尝试创建内部有多个堆栈布局的自定义单元格。但在listview中,仅显示自定义单元格的第一行。这是我的自定义单元格代码: <ListView x:Name="ListViewRides"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Verti
<ListView x:Name="ListViewRides">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" Margin="15">
<StackLayout Orientation="Horizontal">
<Label x:Name="LabelLocationFrom" Text="{Binding PlaceFrom}" Margin="0, 0, 5,0"/>
<Label Text="->"/>
<Label x:Name="LabelLocationTo" Text="{Binding PlaceTo}" Margin="5, 0, 0, 0"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label x:Name="LabelTimeFrom" Text="{Binding TimeFrom}" Margin="0, 0, 5,0"/>
<Label Text="->"/>
<Label x:Name="LabelTimeTo" Text="{Binding TimeTo}" Margin="5, 0, 0, 0"/>
</StackLayout>
<Label x:Name="LabelCustomer" Text="{Binding Customer}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
谢谢你的建议。我想这是我现在看不到的明显的东西。你看不到它可能是因为它不在视野之内,但它就在那里 将
ListView
的RowHeight
属性设置为更高的值以验证这一点
如果我没有弄错的话,
RowHeight
应该能够在您设置为-1并将hassoutrows
设置为true时进行计算。然而,根据我的经验,这并不总是有效的。要使其工作,您可能必须使用一些自定义渲染器。您无法看到它可能是因为它不在视图中,但它在那里
将ListView
的RowHeight
属性设置为更高的值以验证这一点
如果我没有弄错的话,
RowHeight
应该能够在您设置为-1并将hassoutrows
设置为true时进行计算。然而,根据我的经验,这并不总是有效的。要使其正常工作,您可能需要使用一些自定义渲染器。您必须将ListView(…或任何视图)设置为HasUnderRows=True
,并将垂直选项设置为“CenterAndExpand”或“FillAndExpand”或其他适合的选项 必须将ListView(…或任何视图)设置为hasUnderRows=True
,并将垂直选项设置为“CenterAndExpand”或“FillAndExpand”或其他合适的选项 经过这么多的研究,我用测试数据创建了下面的Listview
只需复制粘贴代码并检查结果
<ListView HasUnevenRows="true"
RowHeight="200">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item One</x:String>
<x:String>Item Two</x:String>
<x:String>Item Three</x:String>
<x:String>Item Four</x:String>
<x:String>Item Five</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame BorderColor="Red" Padding="0">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="90" />
<RowDefinition Height="90"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0"
Grid.Column="0"
Color="Yellow" />
<BoxView Grid.Row="0"
Grid.Column="1"
Color="Black" />
<BoxView Grid.Row="1"
Grid.Column="0"
Color="Green" />
<BoxView Grid.Row="1"
Grid.Column="1"
Color="Blue" />
<Label Text="{Binding}"
FontAttributes="Bold"
TextColor="Red"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
项目一
项目二
项目三
项目四
项目五
在做了大量研究之后,我用测试数据创建了下面的Listview
只需复制粘贴代码并检查结果
<ListView HasUnevenRows="true"
RowHeight="200">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item One</x:String>
<x:String>Item Two</x:String>
<x:String>Item Three</x:String>
<x:String>Item Four</x:String>
<x:String>Item Five</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame BorderColor="Red" Padding="0">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="90" />
<RowDefinition Height="90"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<BoxView Grid.Row="0"
Grid.Column="0"
Color="Yellow" />
<BoxView Grid.Row="0"
Grid.Column="1"
Color="Black" />
<BoxView Grid.Row="1"
Grid.Column="0"
Color="Green" />
<BoxView Grid.Row="1"
Grid.Column="1"
Color="Blue" />
<Label Text="{Binding}"
FontAttributes="Bold"
TextColor="Red"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
项目一
项目二
项目三
项目四
项目五
它可能不在视野之内。尝试将列表视图上的行高设置为更大的数字,然后查看是否存在某些内容。您是对的,是否有任何模式可以确定行高?它可能不在视图中。尝试将列表视图上的行高设置为更大的数字,然后查看是否存在某些内容。您是对的,是否有确定行高的模式?