我有一个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,是因为我可以添加swipe来删除。
发布于 2017-08-30 15:20:58
您可以只使用内置的TextCell来实现您想要做的事情。它有一个可绑定的TextProperty和一个可选的DetailProperty,如果您希望在主行下面有一个较小的文本行的话。
IList.ItempTemplate = new DataTemplate(()=>
{
var textCell = new TextCell();
textCell.ContextActions.Add(yourAction);
textCell.SetBinding(TextCell.TextProperty, ".");
return textCell;
}
IList.ItemsSource = _routine_names;
yourAction
的类型为MenuItem,如这里所示
另外,请注意,IList
是System.Collection命名空间中的一个类的名称,所以我会在那里使用其他的名称。
https://stackoverflow.com/questions/45970995
复制