Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions MAUI/DataGrid/conditional-styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,64 @@ public class ForeColorConverter : IValueConverter

![Conditional cell styling based on RowIndex and ColumnIndex in .NET MAUI DataGrid](Images/conditional-styling/maui-datagrid-conditional-datagridcelltyle_basedon_rowcolumnindex.png)

## Customizing Border Color for a Specific Cell in SfDataGrid
You can apply styling to a specific cell in the SfDataGrid by targeting the DataGridCell and using the RowIndex and ColumnIndex properties along with the BorderColor property. This allows you to customize the appearance of individual cells, such as setting a unique border color. Additionally, you can customize the thickness of the border using the [GridLineStrokeThickness](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridStyle.html#Syncfusion_Maui_DataGrid_DataGridStyle_GridLineStrokeThicknessProperty) property.

{% tabs %}
{% highlight xaml tabtitle="MainPage.xaml" %}
<ContentPage xmlns:syncfusion=http://schemas.syncfusion.com/maui>
<ContentPage.Resources>
<ResourceDictionary>
<local:BorderColorConverter x:Key="converter" />
<Style TargetType="syncfusion:DataGridCell">
<Setter Property="BorderColor" Value="{Binding Source={RelativeSource Mode=Self}, Converter={StaticResource converter}}" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>
<Grid>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}"
GridLinesVisibility="Both">

<syncfusion:SfDataGrid.DefaultStyle>
<syncfusion:DataGridStyle GridLineStrokeThickness="5" />
</syncfusion:SfDataGrid.DefaultStyle>
</syncfusion:SfDataGrid>
</Grid>
</ContentPage.Content>
</ContentPage>
{% endhighlight %}
{% highlight xaml tabtitle="BorderColorConverter.cs" %}

public class BorderColorConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var gridCell = value as DataGridCell;

if (gridCell != null)
{
if (gridCell.DataColumn!.RowIndex == 4 && gridCell.DataColumn.ColumnIndex == 3)
return Colors.Blue;

return Colors.Transparent;
}

return Colors.Transparent;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
{% endhighlight %}
{% endtabs %}

![Conditional cell styling based on RowIndex and ColumnIndex in .NET MAUI DataGrid](Images/conditional-styling/maui-datagrid-conditional-datagridcelltyle_bordercolor_basedon_rowcolumnindex.png)

## Style a cell based on cell value
Styling can be applied to a particular cell based on CellValue property by writing the style for the [DataGridCell](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DataGridCell.html) TargetType.

Expand Down