I need to change the selected item color of a listview in my Xamarin.Forms app. So I created a custom renderer...
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;
}
}
But is not working. I also tried to change the SelectionStyle but nothing...
EDIT
In a new project it works. And the code is the same