我不会更改所选记录中的背景颜色。我创建了转换器,但它记录的记录多于一个。我只需要选择一条记录并更改其中的背景颜色
ColorConverter
Get-WmiObject -Class Win32_UserAccount |? {$_.localaccount -eq $true} | select name, fullname
ElementSelectConverter
public class ColorElementSelectionConverter : ElementSelectionConverter<ColorResponseModel>
{
protected override bool Equals(ColorResponseModel selectedElement, ColorResponseModel currentElemnt)
{
return selectedElement.Id.Equals(currentElemnt.Id);
}
}
查看
public abstract class ElementSelectionConverter<T> : IValueConverter where T: class
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var selectedElement = value as T;
if(selectedElement == null) return false;
var viewCell = parameter as ViewCell;
if(viewCell == null) return false;
var currentElemnt = viewCell.BindingContext as T;
if(currentElemnt == null) return false;
return Equals(selectedElement, currentElemnt);
}
protected virtual bool Equals(T selectedElement, T currentElemnt)
{
return selectedElement.Equals(currentElemnt);
}
答案 0 :(得分:0)
要在列表视图中更改所选项目的背景色,请找到此处提供的解决方案:
Change background color of selected listview item
您需要为其创建自定义视单元及其渲染器。
希望这对您有帮助!