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 6232543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:08:04+00:00 2026-05-24T10:08:04+00:00

Hi I need to implement a function that if the value of the binding

  • 0

Hi I need to implement a function that if the value of the binding items is within the specific range cell color should be according to the range.

I have been using Changing Background Color Of DataGrid Cell WPF 4

this works fine but it is for only if that values are there.what if i want to add range i.e from 10 – 20 it is red 21-30 it is blue

added everything and saw an example at the end but the color does not change here is the code

Class

 public class ConvertToBrush : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int tempValue = int.Parse(value.ToString());
            string tempString = "Red";
            if (tempValue >= 0 && tempValue <= 20)
                tempString = "#FF0000";

            if (tempValue > 20 && tempValue <= 40)
                tempString = "#F09300";

            if (tempValue > 40 && tempValue <= 60)
                tempString = "#EDDF00";

            if (tempValue > 60 && tempValue <= 80)
                tempString = "#FFFFFF";

            if (tempValue > 80 && tempValue <= 100)
                tempString = "#85AB00";


            SolidColorBrush brush = new SolidColorBrush();
            BrushConverter conv = new BrushConverter();
            brush = conv.ConvertFromString(tempString) as SolidColorBrush;
            return brush;

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {

            return DependencyProperty.UnsetValue;
        }
    }

XMAL

  <DataGridTextColumn ElementStyle="{StaticResource CentreAlignStyle}" Binding="{Binding TestResults}" Header="Results" IsReadOnly="True" MaxWidth="60" MinWidth="60" >
                                        <DataGridTextColumn.CellStyle>
                                            <Style>
                                                <Setter Property="TextBlock.Background" Value="{Binding TestResults, Converter={StaticResource makeBrush}}" />
                                            </Style>
                                        </DataGridTextColumn.CellStyle>
                                    </DataGridTextColumn>
  • 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-24T10:08:07+00:00Added an answer on May 24, 2026 at 10:08 am

    Don’t use a DataTrigger but just bind the Background to the value and put in a ValueConverter to return the right brush (or no brush at all).

    Edit: What the usage should look like:

    <DataGridTextColumn.CellStyle>
        <Style>
             <Setter Property="Border.Background" Value="{Binding TestResults, Converter={StaticResource BrushConverter}}" />
        </Style>
    </DataGridTextColumn.CellStyle>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If we need to implement a function that takes an array of integers and
I need to implement a WSDL interface (HTTP binding) for a variable list function.
There is a good function that I need, which is implemented in the Java
I need to implement a function for moving records up and down (sorting) and
I need to implement a 4-to-1 function in Veriog. The input is 4 bits,
I have a skeleton of a project I need to implement a Doubly Linked
I need to implement a function which returns a TDictionary, without specifying the exact
I'm trying to implement a transparent cache that can load a specific object when
I need to create a function in SQL Server that returns a string. In
I have a function calc_dG that, for any array corresponding to a short DNA

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.