Customise cell background

I'm trying to customise the cell background, and none of the SyncFusion examples work. The idea is to modify the Style, but I don't know which TargetType to use. The documentation refers to GridCell, but I get an InvalidOperationException saying that "'GridCell' TargetType does not match type of element 'GridCell'". Other documentation says to target VirtualizingCellsControl, but the compiler says that it doesn't have a Background property. So what should I use as the TargetType? Or is there another way to change the cell background?


I've attached a project which demonstrates this issue.


Attachment: GridCell_fc132cdd.zip

1 Reply

DM Dhanasekar Mohanraj Syncfusion Team March 14, 2023 02:39 PM UTC

Hi Russell,

We have checked the reported issue with the provided details. This issue occurs because of ambiguity in the GridCell and it can be resolved by adding a separate namespace for the DataGrid as shown below,


xmlns:grid="clr-namespace:Syncfusion.UI.Xaml.Grid;assembly=Syncfusion.SfGrid.WPF"

<grid:SfDataGrid ItemsSource="{Binding Items}">

    <grid:SfDataGrid.Columns>

        <grid:GridCheckBoxColumn MappingName="Selected" AllowEditing="True">

            <grid:GridCheckBoxColumn.CellStyle>

                <Style TargetType="grid:GridCell">

                    <Setter Property="Background" Value="LightBlue"/>

                </Style>

            </grid:GridCheckBoxColumn.CellStyle>

        </grid:GridCheckBoxColumn>

        <grid:GridTextColumn MappingName="Name">

            <grid:GridTextColumn.CellStyle>

                <Style TargetType="grid:GridCell">

                    <Setter Property="Background" Value="LightBlue"/>

                </Style>

            </grid:GridTextColumn.CellStyle>

        </grid:GridTextColumn>

    </grid:SfDataGrid.Columns>

</grid:SfDataGrid>


Here, we have attached the modified sample with the above suggestion, please have a look at this.


Regards,

Dhanasekar M.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



Attachment: GridCell_427c299e.zip

Loader.
Up arrow icon