如何在xamarin形式的列表视图中显示从1到如此的行号?
我有一个要求,我必须创建一个listView来为每个商品添加商品编号.我有一个在项目模型中放入数字的想法,但我无法弄清楚.
I have got a requirement where I have to create a listView which adds item number with each item. I have got an idea of putting a number in model of item but I am unable to figure that out.
最简单的方法应该是向绑定到ListView.ItemsSource
的ViewModel
添加一个附加属性Index
屏幕.
The easiest way should be to add one additional property Index
to the ViewModel
that is bound to the the ListView.ItemsSource
and then simply represent it on the screen.
或者,如果需要多次使用枚举的ListView
,则可以创建可重复使用的控件,并将逻辑从ViewModel
移到UI
层.
Alternatively, if there is a need to use an enumerated ListView
multiple times you could create a reusable control and move the logic from the ViewModel
to the UI
layer.
所以这一切都取决于您的需求.
So it all depends on your needs.