Xamarin.Forms - 使用纯XAML创建ListView

10

我们有几个屏幕在iOS上应有效地成为 UITableViews,这些屏幕有固定数量的行和不同类型的单元格。

在Xamarin.Forms中是否有一种方法可以定义它,而不必设置与ItemsSource的绑定?例如,如果我只想定义两个 EntryCells ,然后是一个 TextCell

我的第一个尝试是这个示例,但我只看到每行中等效于 Cell.ToString()的内容:

  <ListView>
    <ListView.ItemsSource>
        <x:Array Type="{x:Type Cell}">
            <EntryCell Text="{Binding Phone}" />
            <EntryCell Text="{Binding Code}" />
            <TextCell Text="LOGIN" Command="{Binding Login}"/>
        </x:Array>
    </ListView.ItemsSource>
  </ListView>
1个回答

1

如果您想要具有不同模板/布局的静态单元格,您尝试过Xamarin.Forms TableView吗?http://iosapi.xamarin.com/?link=T%3aXamarin.Forms.TableView

<TableView>
    <TableView.Root>
        <TableSection Title="Login">        
            <EntryCell Text="{Binding Phone}" />
            <EntryCell Text="{Binding Code}" />
            <TextCell Text="LOGIN" Command="{Binding Login}"/>
        </TableSection>
    </TableView.Root>
</TableView>

承认,在编写时这似乎会给您提供一个不可定制的部分标题(但这可能会得到改善)。

1
我们尝试过这样做,但是不想在UI中为TableSection添加任何标题。但是如果将Title设置为空,Android上仍会有一个空白可点击的行作为标题。ListView没有这个问题。 - jonathanpeppers
就此而言,这个空头在Xamarin.Forms v2.5.0.91635中仍然存在,因此仍不是一个理想的替代品。 - patridge

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接