We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize the Foreground color for cells in a column based on the cell content?

Platform: Xamarin.Android |
Control: SfDataGrid |
Published Date: January 22, 2016 |
Last Revised Date: November 4, 2016
Tags: styling

SfDataGrid displays all the text values in GridCells with a default Foreground color of RGB values 51. However SfDataGrid allows you to customize the Foreground color of the GridCells for the entire view and also to some specific cells based on conditions. 

To change the Foreground color of the GridCells for the entire view, you can use the SfDataGrid.GridStyle property and set the custom style to change the foreground color. For more details please refer our user documentation in the below link.


In case, if your requirement is to change the Foreground color based on the cell value, then you can achieve this by creating custom GridCell derived from GridCell in SfDataGrid. SfDataGrid also provides options to load views inside the GridCell or to draw the cell value directly in the canvas based on your application requirements. Drawing the contents directly in the canvas gives you much better performance.


Refer the below code example for loading views inside the GridCell to customize its Foreground color based on cell value. The foreground of the GridCells are applied with red color for negative values and black for positive values.



Refer the below code example for directly drawing the cell values on the GridCell’s canvas. The foreground of the GridCells are applied with red color for values < 1010 and black for positive values while drawing in the canvas.


Refer the following screenshot for the final outcome

Refer Sample:

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile