针对Xamarin.Forms中的ListView项添加序列号

针对Xamarin.Forms中的ListView项添加序列号,listview,xamarin.forms,listviewitem,Listview,Xamarin.forms,Listviewitem,我使用了RepeaterView并将ItemSource绑定到List <local:RepeaterView ItemsSource="{Binding Approvals}"> <local:RepeaterView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout>

我使用了RepeaterView并将ItemSource绑定到List

<local:RepeaterView ItemsSource="{Binding Approvals}">
   <local:RepeaterView.ItemTemplate>
           <DataTemplate>
                 <ViewCell>
                 <StackLayout>
                     ........
                 </StackLayout>
             </ViewCell>
         </DataTemplate>
    </local:RepeaterView.ItemTemplate>
</local:RepeaterView>

........
这是列表类型属性

private List<ApprovalVM> _Approvals;
    public List<ApprovalVM> Approvals
    {
        get { return _Approvals; }
        set { SetValue(ref _Approvals, value); }
    }

私有列表

我认为您必须创建另一个列表来添加序列号属性

    class Temp { 
    public List<ApprovalVM> Approvals{get;set;} 
    public int SerialNo{get;set;}
}
class Temp{
公共列表批准{get;set;}
public int SerialNo{get;set;}
}
然后创建临时列表并逐个添加项&增加序列号。
并在RepeaterView设计中绑定SerialNo。

当你说“序列号”时,你真的是指“顺序索引”,如1,2,3,4…?可能重复的“序列号”通常与“索引号”的含义不同,因此,您对该术语的使用非常混乱。我的问题是相同的,但我没有从该问题中得到答案。我的RepeaterView.ItemSource已绑定到列表属性,在该答案中,他要求将该属性绑定到索引(新)这个问题中提供的答案也应该适用于您的场景-要么向VM添加属性,要么创建一个自定义控件来处理它