首页 > 解决方案 > 当 ItemSource 只是一个 List 时如何自定义 TextCell?

问题描述

我想在 Xamarin.Forms 中创建一个字符串的 ListView,但我没有在文档中找到如何做到这一点。

  <ListView>
            <ListView.ItemsSource>
                <x:Array Type="{x:Type x:String}">
                    <x:String>mono</x:String>
                    <x:String>monodroid</x:String>
                    <x:String>monotouch</x:String>
                    <x:String>monorail</x:String>
                    <x:String>monodevelop</x:String>
                    <x:String>monotone</x:String>
                    <x:String>monopoly</x:String>
                    <x:String>monomodal</x:String>
                    <x:String>mononucleosis</x:String>
                </x:Array>
            </ListView.ItemsSource>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextCell>
                     <!--How to customize this textcell with the content of the array?-->
                    </TextCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

我试过这个,但我只得到字典中不存在密钥的错误。当 ItemSource 只是字符串时,如何自定义 ListView-Cell?

标签: xamlxamarinxamarin.forms

解决方案


使用.语法绑定当前对象

<TextCell Text="{Binding .}" />

推荐阅读