Xamarin表单-在一个ListView中绑定多个TextCell [英] Xamarin Forms - Binding Multiple TextCells in one ListView
问题描述
我在将多个TextCell绑定到ListView时遇到麻烦.如果只有一个,它会很好地工作,但是在添加更多时会给出XamlParseException.尝试绑定标签时发生相同的异常.这就是为什么我不得不使用TextCell的原因.有什么解决方案?
I am having trouble binding multiple TextCells in a ListView. It works fine if there's only one, but gives XamlParseException on adding more. The same Exception occurs while trying to bind a Label. That's why I had to use a TextCell. What's the solution?
<ListView x:Name="pList">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell x:Name="a" Text="{Binding ReceiverName}" TextColor="White" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
推荐答案
从您对其中一项答案的评论看来,这就是您想要的
From your comment on one of the answers, it looks like this is what you want
<ListView x:Name="pList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label Text="{Binding ReceiverName}" TextColor="White" />
<Label Text="{Binding SecondText}" TextColor="White" />
<Label Text="{Binding ThirdText}" TextColor="White" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这将垂直显示3个标签.您遇到的问题是DataTemplate不能有多个孩子.解决该问题的标准方法是使用诸如StackLayout之类的布局控件.
This will display 3 Labels vertically.The problem you were having is that the DataTemplate can't have more than one child. The standard way around that is to use a layout control such as StackLayout.
请参阅此页面以获取更多信息: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/layouts/
Please see this page for more information: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/layouts/
这篇关于Xamarin表单-在一个ListView中绑定多个TextCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!