我在 ListView 上绑定了一个 ObersvableCollection。
我想改变我的 ListView 的行颜色。
我找到了很多代码,但对我不起作用...如果你可以分享一个示例/样本!
像这样 :
但我不知道我该怎么做?
我使用 Visual Studio 2015 / Xamarin 表单。
我的项目必须兼容 Android 和 IOS。
感谢您的帮助!
您可以为此使用自定义 ListView。如果您的 Cell 继承自ViewCell
.
public class AlternatingListView : ListView
{
public AlternatingListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy)
{
}
protected override void SetupContent(Cell content, int index)
{
base.SetupContent(content, index);
var viewCell = content as ViewCell;
viewCell.View.BackgroundColor = index % 2 == 0 ? Color.Blue : Color.Red;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)