【发布时间】:2017-12-17 02:09:39
【问题描述】:
我需要在我的 Xamarin.Forms 应用程序中更改列表视图的选定项目颜色。 所以我创建了一个自定义渲染器...
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 但什么都没有......
编辑
在一个新项目中它可以工作。而且代码是一样的
【问题讨论】:
标签: c# ios listview xamarin.ios xamarin.forms