代码之家  ›  专栏  ›  技术社区  ›  justin

Xamarin表单列表视图项资源问题

  •  1
  • justin  · 技术社区  · 7 年前

    我有一个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的原因是,我可以将滑动添加到删除。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Timo Salomäki    7 年前

    你可以只使用内置的 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

    IList 是系统中类的名称。集合命名空间,所以我会在那里使用其他内容。