Xamarin.forms 如何使用XAML在ListView中实现ItemTemplate

Xamarin.forms 如何使用XAML在ListView中实现ItemTemplate,xamarin.forms,Xamarin.forms,如何使用XAML在ListView中实现ItemTemplate 如果我不使用ItemTemplate,那么我的绑定工作正常,不会收到任何错误。 但是,我想格式化我的列表视图。 因此,我尝试使用ItemTemplate,但仍遇到运行时异常: Xamarin.Forms.Xaml.XamlParseException:位置30:30。无法分配属性“视图”:在“Xamarin.Forms.TextCell”和“X 我收到一个运行时异常,其XAML如下: <ListView Grid.Row="

如何使用XAML在ListView中实现ItemTemplate

如果我不使用ItemTemplate,那么我的绑定工作正常,不会收到任何错误。 但是,我想格式化我的列表视图。 因此,我尝试使用ItemTemplate,但仍遇到运行时异常:

Xamarin.Forms.Xaml.XamlParseException:位置30:30。无法分配属性“视图”:在“Xamarin.Forms.TextCell”和“X

我收到一个运行时异常,其XAML如下:

<ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Services}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <TextCell Text="{Binding Name}" Detail="{Binding Description}" />
                </ViewCell.View>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

有什么建议吗?

  • ViewCell是一个可用于创建自定义单元格布局的类
  • TextCell是具有预定义布局的预定义单元格
不能在另一个单元格中使用单元格(如ViewCell中的TextCell)

您可以创建如下自定义单元格:


或者使用预定义的:



此处是预定义单元格的列表:

ViewCell.View不适用于网格?我无法插入网格。它适用于: