我无法在ListView中绑定多个TextCell。如果只有一个,它工作正常,但在添加更多时给出XamlParseException。尝试绑定Label时发生相同的异常。这就是我必须使用TextCell的原因。解决方案是什么?
<ListView x:Name="pList">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell x:Name="a" Text="{Binding ReceiverName}" TextColor="White" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:2)
根据你对其中一个答案的评论,看起来这就是你想要的
<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等布局控件。
请参阅此页面以获取更多信息:http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/layouts/
答案 1 :(得分:0)
根据您已粘贴的代码进行猜测我说问题在于您为控件命名。移除a:Name
,然后重试。
如果这没有帮助,也可以发布例外细节。
答案 2 :(得分:0)
您需要在数据模板中添加“ViewCell”,如下所示:
<ListView x:Name="pList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<TextCell x:Name="a" Text="{Binding ReceiverName}" TextColor="White" />
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 3 :(得分:0)
TextCell还有一个详细属性:
<TextCell x:Name="a" Text="{Binding ReceiverName}" Detail="{Binding AnotherName}" TextColor="White" />