【发布时间】:2015-09-13 03:24:36
【问题描述】:
如何使用数据绑定在 ListView 中创建 Grid?我正在使用 Xamarin.Forms 创建这个应用程序。
如果我不知道需要多少行和列,如何在 ListView 绑定中动态创建 Grid?
这是我目前所拥有的:
<ListView x:Name="List" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid Padding="10,10,10,10">
<Grid.RowDefinitions>
<RowDefinition Height="200"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackLayout BackgroundColor="#313FA0" Grid.Row="0" Grid.Column="0" HeightRequest="200" WidthRequest="200">
<Label Text="{Binding NUMBER}" FontSize="50" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
<Label Text="{Binding NAME}" FontSize="30" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
在此代码中,仅创建了一行和一列。如果我有多个数据点,我该如何解决这个问题?例如,如果我需要一行两列。
提前致谢。
【问题讨论】:
标签: c# listview xamarin xamarin.forms