我需要更改Xamarin.Forms应用程序中的列表视图的选定项目颜色。 所以我创建了一个自定义渲染...Xamarin.Forms iOS listview选定的项目颜色
PCL C#:
public class DarkViewCell : ViewCell {}
PCL XAML:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<local:DarkViewCell>
<ViewCell.View>
... Stuff ...
</ViewCell.View>
</local:DarkViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
的iOS
public class DarkViewCellRenderer : ViewCellRenderer
{
private UIView bgView;
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
cell.BackgroundColor = UIColor.Black;
cell.TextLabel.TextColor = UIColor.White;
if (bgView == null)
{
bgView = new UIView(cell.SelectedBackgroundView.Bounds);
bgView.Layer.BackgroundColor = UIColor.FromRGB(48,48,48).CGColor;
bgView.Layer.BorderColor = UIColor.FromRGB(48, 48, 48).CGColor;
bgView.Layer.BorderWidth = 2.0f;
}
cell.SelectedBackgroundView = bgView;
return cell;
}
}
但不工作。我也试图改变SelectionStyle但没有...
编辑
在一个新项目,它的工作原理。和代码是一样的
这是我尝试的第一件事 –
自定义渲染器中的其他任何东西是工作还是根本不工作?我只是从我自己的一个项目中复制了一段代码,它完全按照需要工作。 –
更新了我的答案。 –