Hi Guys I´ve got a ListView which is bound to the ObservableCollection mPersonList. The Class Person got an enum Sex. What i want to do is to set the background of the ListViewItem to green if the person is male and to red if the person is female.
Thanks for the answers!
i tried it like this but whats wrong with it?
<Style x:Key="CustomListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="{Binding Path=Status, Converter={StaticResource sexEnumToColor}}" />
</Style>
and:
public class SexEnumToColor : IValueConverter
{
#region IValueConverter Member
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Sex tempSex = (Sex)value;
Brush retval;
switch (tempSex )
{
case Sex.Male:
retval = Brushes.Blue;
break;
case Sex.Female:
retval = Brushes.Red;
break;
default:
retval = Brushes.Black;
break;
}
return retval;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}