Conditional stylyng for the datagrid cell based on cell value

Hi,

I've been doing upgrade from Xamarin.Forms sfDatagrid to .NET MAUI sfDtatgrid.

I use DataTable for the sfDataGrid.ItemSource and I need cell specific:

- cell background

- font color

- cell border color

based on data value which is updated dynamically (while ItemSource DataTable values are changed). In Xamarin sfDataGrid I subscribed to QueryCellStyle event which is not here in .NET MAUI sfDtatgrid as I got it.

I implemented Style in code behind following the https://help.syncfusion.com/maui/datagrid/conditional-styling#style-a-cell-based-on-cell-value       like this:

            var dataGridCellStyle = new Style(typeof(DataGridCell));


            dataGridCellStyle.Setters.Add(new Setter

            {

                Property = DataGridCell.BackgroundProperty,

                Value = new Binding()

                {

                    Path = ".",

                    Source = new RelativeBindingSource(RelativeBindingSourceMode.Self),

                    Converter = new BackgroundColorConverter(),

                    ConverterParameter = this

                }

            });

and add it to Resources collection of sfDataGrid.

There are following issues I faced:

1) Convert method of BackgroundColorConverter is not invoked when I alter value of elements in ItemSource. Can you please confirm that it should work the same way as in Forms solution or suggest the way to overcome it, having in mind that invalidating whole view after single cell update is the last option I would take?

2) Only one Setter is applied, for example Background, but not TextColor, while both works if there is only one setter. Can you give some example or pinpoint the possible issue?

3) There are no property to update border of the cell (color or thickness). Is it possible?

Thanks in advance.



1 Reply

SD Sethupathy Devarajan Syncfusion Team January 31, 2025 01:55 PM UTC

Hi Serhii,


Thank you for contacting us,


Query

Response

1) Convert method of BackgroundColorConverter is not invoked when I alter value of elements in ItemSource. Can you please confirm that it should work the same way as in Forms solution or suggest the way to overcome it, having in mind that invalidating whole view after single cell update is the last option I would take?

 

 

In MAUI, the convert method of the backgroundColorConverter is not invoked when you alter any value in the item source, whereas in Xamarin it works using QueryCellStyle.

 

In MAUI, we utilized the framework's implicit style, and the convert method is only triggered when the binding context is changed. In contrast, in Xamarin, we used the queryStyle event and manually invoked it, so it triggered whenever a value changed.

 

Could you please provide your use case so that we can offer you an alternative solution?

2) Only one Setter is applied, for example Background, but not TextColor, while both works if there is only one setter. Can you give some example or pinpoint the possible issue?

 

We checked this with the attached sample, and it worked fine on our end. If you are still encountering the same problem, we kindly request that you modify the attached sample to reproduce the issue and provide additional details. This will greatly assist us in further investigating the issue and providing an appropriate solution as quickly as possible.

There are no property to update border of the cell (color or thickness). Is it possible?

You could change the grid line color and gridline stroke thickness. We had shared the UG link for your reference.

 

Ug links:



Regards,

Sethupathy D.


Attachment: SfDataGridSample_fb3d1693.zip

Loader.
Up arrow icon