Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
720
How to change background color of a particular row using XAMGrid ?
posted

Hi,

We are using XAMGrid and we want to change background color of some of grid rows as per some conditions. Suppose I have three Column Name, Dob, Address. Now  I will compare DOB with current date If It will be greater than 18 years In this scenario this particular row background color will be change in Yellow Color. If It will be less than 15 Years In this scenario this particular row background color will be change in Yellow Color.

Please let us aware. How we can approach it. and here We are using XAMGRID.

Thanks

Parents
  • 34830
    Offline posted

    Hello Pri kanwar,

    In order to do this in the XamGrid, I would recommend creating a Style for CellControl and populating the Style.Triggers collection with a DataTrigger. The data context of the CellControl elements in a particular XamGrid will be the underlying data item that makes up the Row that the cell sits in, and so you could bind directly to your Dob property.

    I imagine your Dob property is a DateTime type, and so I would then recommend a converter for this binding that determines whether or not the Dob property represents a time that is either greater than 18 years or less than 15 years away. You can then return a value to your DataTrigger that tells it whether or not to apply a particular setter, in this case, for the Background property of your CellControl objects.

    I have attached a sample project that demonstrates this approach, in which a row will be colored yellow if the date of birth was over 25 years away. The data source is randomly generated to subtract a random number of years between 1 and 50 for each record.

    I hope this helps you. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XamGridDynamicRowColorCase.zip
Reply Children