C# Xamarin表单列表视图项目资源问题

C# Xamarin表单列表视图项目资源问题,c#,listview,xamarin,xamarin.forms,datatemplate,C#,Listview,Xamarin,Xamarin.forms,Datatemplate,我有一个ListView及其ItemsSource ListView IList = new ListView(); IList.ItemsSource = _routine_names; 为了自定义我正在执行的每个项目的数据模板: IList.ItemTemplate = new DataTemplate(()=> { Label Routine_Name = new Label(); // should be_routine_names

我有一个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处理程序),但没有文本,应该是_例程_名称中的任何内容

我的问题是如何使DataTemplate中的标签成为_例程_名称中的项


我添加数据模板的原因是,我可以将滑动添加到删除中。

您只需使用内置的数据模板即可。它有一个可绑定的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命名空间中的一个类的名称,因此我将在那里使用其他名称。

您可以使用内置名称来完成您尝试执行的操作。它有一个可绑定的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命名空间中的一个类的名称,因此我将在那里使用其他名称。

第二个参数中的“例程名称”应该是什么?我的_例程\u名称只是一个可观察的字符串集合。@justin如果它只是可观察的集合,您可以将绑定设置为
,它将指向集合中的每个字符串。我更新了我的答案以反映变化。@justing你让它与最新的变化一起工作了吗?@justin很高兴听到这个消息!第二个参数中的“例程名称”应该是什么?我的_例程\u名称只是一个可观察的字符串集合。@justin如果它只是可观察的集合,您可以将绑定设置为
,它将指向集合中的每个字符串。我更新了我的答案以反映变化。@justing你让它与最新的变化一起工作了吗?@justin很高兴听到这个消息!