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
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,AndrewAssociate Developer
Thanks you so much for your wonderful support. As per your suggestion and sample source I have added trigger and converter and background color also going to change as per converter value.
But here I just wish to know If we add multiple background color according to age. suppose Age will is 10 then color will be green. If Age will is 20 then color will be yellow, If age is 30 then color will be red and so on. I am just little bit stuck how we can approach it.
<Style.Triggers> <DataTrigger Binding="{Binding ExpirationDate, Converter={StaticResource expireDateConv}}" Value="True"> <Setter Property="Background" Value="Yellow"/> </DataTrigger> </Style.Triggers>
In above style background color already set yellow as per converter True False value. How we can set more than two background values?