Issue
I wan't change the background color in the selected record. I create converter but it marks out more records than one. I need only one record to be selected and change the background color in it
ColorConverter
public class ColorElementSelectionConverter : ElementSelectionConverter<ColorResponseModel>
{
protected override bool Equals(ColorResponseModel selectedElement, ColorResponseModel currentElemnt)
{
return selectedElement.Id.Equals(currentElemnt.Id);
}
}
ElementSelectConverter
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);
}
View
<ViewCell x:Name="ColorViewCell">
<Grid Margin="0,0,0,0" HeightRequest="36" VerticalOptions="Center">
<Grid.Triggers>
<DataTrigger TargetType="Grid"
Binding="{Binding Path=BindingContext.Color, Source={x:Reference Name=CarColorListPopup},Converter={StaticResource ColorElementSelectionConverter},
ConverterParameter={x:Reference Name=ColorViewCell}}" Value="true">
<Setter Property="BackgroundColor" Value="#388FEE" />
</DataTrigger>
Solution
I was using ItemSelected, but the selected item wasn't getting deselected unless until I select any other item in the ListView. I replace ItemSelected by ItemTapped.
Answered By - Dev007
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.