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.Forms |
Control: SfDataGrid
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 using the CellStyle property in the GridColumn. You can write converters for the style properties based on your requirements.

Refer the below code example in which foreground color of the StudentsMarks column is customized based on conditions written in the converter.

    <local:StyleConverterForMarks x:Key="result"/>
<sfgrid:GridTextColumn MappingName="StudentMarks" >
    <Style TargetType="sfgrid:GridCell">
      <Setter Property="Foreground"
                   Value="{BindingStudentMarks,Converter={StaticResource result}}" />


Refer the below code example for writing a converter to customize the cell foreground based on conditions.

public class StyleConverterForMarks : IValueConverter
public object Convert(object value, Type targetType, object parameter,
                      System.Globalization.CultureInfo culture)
   int _value = (int)value;
   if (_value >= 45)
   return Color.Green;
   return Color.Red;
public object ConvertBack(object value, Type targetType, object parameter,
                                            System.Globalization.CultureInfo culture)
   return value();


Refer the following screenshot for the final outcome

DataGrid customize the cell foreground based on conditions

For more details about applying conditional styles for a column in SfDataGrid, please refer the below user documentation link.



You can download the working sample for this KB from the below link.


2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
Will Ngo
Nov 25, 2016
gose to page not found.
Miroslav Nemec
May 17, 2017
I created my grid dynamically and I need change background color from code behind on click action of button. Is it possible....? Reply

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