我有一个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} } }; });
我的问题是如何使DataTemplate中的标签成为\u routine\u名称中的项?
我添加DataTemplate的原因是,我可以将滑动添加到删除。
你可以只使用内置的 TextCell
IList.ItempTemplate = new DataTemplate(()=> { var textCell = new TextCell(); textCell.ContextActions.Add(yourAction); textCell.SetBinding(TextCell.TextProperty, "."); return textCell; } IList.ItemsSource = _routine_names;
yourAction 如图所示为MenuItem类型 here
yourAction
IList 是系统中类的名称。集合命名空间,所以我会在那里使用其他内容。
IList