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

Related Questions

I have a WPF Datagrid binded to some properties in my ViewModel <DataGrid AutoGenerateColumns=False
I have a nice WPF DataGrid binded to a collection of objects. Everything works
I have binded a list with Editable WPF DataGrid I want to get only
I currently have a WPF DataGrid binded to a DataSet via the DataGrid's ItemsSource
I have List<List<double>> with values and wpf datagrid. How can I set this as
I have a datagrid from wpf Toolkit, with the itemsource binded to a Observable<Item>
I have a WPF DataGrid with some styling, properties and events. I want to
I have a WPF DataGrid UserControl with enum property. public List<myEnum> dataList = new
I have a WPF DataGrid. The DataGrid is bound to an IList. The list
I have a WPF DataGrid control that is binding to a collection of objects.

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.