DataGridCell Style Converter Access Row

Based on the example of conditionally styling a cell:  Conditional Styling in .NET MAUI DataGrid control | Syncfusion®

Does anyone have a suggestion on how I could access the entire row data for that cell in the converter?  The example passes the current cell value as the 'value' as the binding but I need to access the other columns in order to determine the correct style to apply.


1 Reply

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

Hi Raymond,


You need to retrieve the entire row data in the converter. You can achieve this with the code snippet below. We have shared a simple sample for your reference.


Code snippet:
 

// Xaml page

<ContentPage.Resources>

    <local:ColorConverter x:Key="converter" />

    <Style TargetType="syncfusion:DataGridCell">

        <Setter Property="Background"

                Value="{Binding Source={RelativeSource Mode=Self}, Converter={StaticResource Key=converter}}" />

    </Style>

</ContentPage.Resources>



// Xaml.cs page
 

 public class ColorConverter : IValueConverter

 {

     object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo info)

     {

         var rowData = (value as DataGridCell).BindingContext as Employee;

         if (rowData != null && rowData.EmployeeID == 1005)

         {

             return Colors.LightBlue;

         }

         else

             return Colors.White;

     }

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

     {

         throw new NotImplementedException();

     }

 }


If you have any misunderstandings or if your needs differ, please provide clear details about your use case. You can include additional information regarding the expected behavior. This extra detail will enable us to thoroughly address your request and provide an appropriate solution.

regards,

Sethupathy D.


Attachment: SfDataGridSample_5d2c540.zip

Loader.
Up arrow icon