1
我有一个ListView及其ItemsSource。Xamarin表单ListView ItemsSource问题
ListView IList = new ListView();
IList.ItemsSource = _routine_names;
为了自定义数据模板的每个项目我做:
IList.ItemTemplate = new DataTemplate(()=>
{
Label Routine_Name = new Label(); // should be_routine_names
return new ViewCell
{
View = new StackLayout{
Children = {Routine_Name}
}
};
});
当我运行,这是我的显示ListView和列表项确实存在(它们的onclick处理程序工作),但没有文字,应该是_routine_names中的任何文字。
我的问题如何让DataTemplate中的标签成为_routine_names中的项目?
我添加DataTemplate的原因是我可以添加滑动删除。
什么是第二个参数中的“Routine_Name”?我的_routine_names只是一个字符串的ObservableCollection。 – justin
@justin如果它只是ObservableCollection,您可以将绑定设置为'.',它将指向集合中的每个字符串。我更新了我的答案以反映变化。 –
hankide
@justing你有没有得到它与最新的变化? – hankide