0
我试图在ListView
组件中显示两个TextCell
。五月MainPage.xaml
代码:无法显示两个TextCell
<StackLayout>
<Button Text="Go To Map Page" Clicked="Button_OnClicked"/>
<ListView x:Name="MyList">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" />
<TextCell Text="{Binding Age}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
CS代码:
namespace App20
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyList.ItemsSource = new List<Person>
{
new Person()
{
Name = "Dima",
Age = 20
},
new Person()
{
Name = "Roma",
Age = 21
},
new Person()
{
Name = "Masha",
Age = 19
}
};
}
private async void Button_OnClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new MapPage());
}
}
}
如果我只显示元素之一(姓名,年龄),一切工作正常。如果我试图显示他们两个我的应用程序挂起。
第二个问题。为什么只有TextCell
有效?我试图用Button
和Label
,并得到例外。
下面是截图:
创建自己的自定义单元格的布局,我认为这是一个重复:https://stackoverflow.com/questions/25052746/xamarin-forms-binding-multiple-textcells-in-one-listview – cotnic
你必须为你的数据模板使用一个容器视图,例如'StackLayout'或'Grid' – Milen