0 c# xaml listview colors xamarin.forms
我绑定了我的 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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6771 次 |
| 最近记录: |