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

  • Home
  • SEARCH
  • 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 1006243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:25:38+00:00 2026-05-16T08:25:38+00:00

I have a WPF Datagrid binded with list of interface objects. Consider, ClsEmployee class

  • 0

I have a WPF Datagrid binded with list of interface objects.
Consider, ClsEmployee class implements I_Employee interface with properties Empl_Id, Empl_Name, Department, Address and City_name.

List _emplList;

consider, _emplList has 10 items.

dgEmployeeGrid.ItemsSource = _emplList;

Question:
Now, if the user clicks on a button, then i should be able to read the City_name. Based on the City_name, i should be able to set the color (Color can be different for each row) for the rows dynamically through C# code.

Please help me how to do this?

Thanks in advance!

  • 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-16T08:25:38+00:00Added an answer on May 16, 2026 at 8:25 am

    Build a ValueConverter that takes in a “value” of the appropriate type in the grid, and then bind the Background color of the row to that field with the ValueConverter in there to provide the Color brush or whatever other kind of brush (that makes sense) that you’d like to put in there.

    EDIT

    Here is a Converter that converts a bool to a Brush color. This class has two properties called “True” and “False” which we set a Brush to that will be used when the boolean value matches the property. The converter is one way and does not convert brushes back to boolean values.

    XAML to create instance of the Converter and set properties

    <cga:BoolToBrushConverter x:Key="trueIsGreen" 
        True="Green" 
        False="Red"/>
    

    C# Converter Code

    [ValueConversion(typeof(bool), typeof(Brush))]
    public class BoolToBrushConverter : IValueConverter
    {
        public Brush True
        {
            get; set;
        }
    
        public Brush False
        {
            get; set;
        }
    
        public object Convert(object value, Type targetType, 
                              object parameter, CultureInfo culture)
        {
            if (targetType != typeof(Brush))
            {
                return null;
            }
    
            return ((bool) value) ? True : False;
        }
    
        public object ConvertBack(object value, Type targetType, 
                                  object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Example of binding value and convert to a field on an object that takes brushes

    <Ellipse Width="10" Height="10" 
           Fill="{Binding Path=Reviewer.IsMentor, Mode=OneWay, 
                          Converter={StaticResource trueIsGreen}}"/>
    

    I’m assuming you are familiar with databinding in WPF and won’t elaborate that aspect of the solution but when the Reviewer.IsMentor is true, the Converter will provide a “Green” brush (sent when the Converter was created) to the Fill property of the ellipse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Let me quote an article about timers by John Resig,… May 16, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer I got this answer from Igor Tandetnik on sqlite-users: INSERT… May 16, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer typeof(MyType) .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(m =>… May 16, 2026 at 5:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have binded a list with Editable WPF DataGrid I want to get only
I have wpf datagrid, in one of columns, I checkboxes added in it, now
I have wpf datagrid with number of template columns. some of them have textbox
I have a WPF DataGrid with some data. You can add rows through a
I have a WPF datagrid and it works great but I notice some sort
I have a WPF DataGrid bound to ObservableCollection . Each item in my collection
I have a WPF Datagrid control. I want to apply style for scrollbars. It
I have a wpf datagrid which is bound to an observable collection. Currently I
I have created a custom style for my WPF datagrid by overriding its control
I have a WinDataGrid class that extends from an Infragistics UltraGrid . I have

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.