Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 675637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:50:23+00:00 2026-05-14T00:50:23+00:00

I´ve got a ListView which is bound to the ObservableCollection mPersonList. The Class Person

  • 0

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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:50:23+00:00Added an answer on May 14, 2026 at 12:50 am

    You can bind sex property with converter. Something like this:

    <ListView>
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextBox Text="{Binding name}" Background="{Binding sex, Converter={StaticResource converterSexToColor}}" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    and converter:

    public class ConverterSexToColor : IValueConverter
    {
        public object Convert(object value, Type targeTtype, object parameter, System.Globalization.CultureInfo culture)
        {
            return (Sex)value == Sex.Male ? Brushes.Green :  Brushes.Red;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple ListView which pulls data from an ObservableCollection and I'm using
What I want to do : run a background thread which calculates ListView contents
I've got a TabControl which contains a nested ListView. The ListView is bound to
I got a ListView with an ItemsSource collection, where ObservableCollection<string> is set. And, the
In my View I got a ListView bound to a CollectionView in my ViewModel,
I got a ListView (wrapped in a ScrollViewer), which resizes itself if the elements
I've got this code which basically loops through a set of folders and subfolders
I've got a listbox from which I'm dragging into the ListView. Now I have
I got a trivial code involving a ListView and a ArrayAdapter which throws a
So, both ListBox.ObjectCollection and ListView.ListViewItemCollection implement the IList class, which provides Add and Remove

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.