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

Cell styling sometimes do not work

This type of styling sometimes do not work properly..

        <Style TargetType="syncfusion:GridCell" x:Key="nullCellStyle">

            <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self},

                Converter = {StaticResource changebackground}}" />

        </Style>

Full code in attachment (issue occurs when scrolling)



not always in same place.. 






Attachment: SyncfusionTests_101290a3.zip

1 Reply 1 reply marked as answer

SJ Sathiyathanam Jeyakumar Syncfusion Team January 3, 2023 03:54 PM UTC

Hi Krzysztof,

We reviewed the attached sample and noticed that you are using a converter to change the background color of the grid cells. In SfDataGrid, UI elements are only created for visible items and are reused for other items when scrolling. For example, if you have 1000 records but only 20 rows are visible at a time, SfDataGrid will create elements for those 20 rows and reuse them for the remaining rows, updating only the data. This is why the style mismatching issue occurs when scrolling. To resolve this issue, you can use the CellStyleSelector concept in SfDataGrid which is to used update the cell styles at runtime.

App.Xaml

<Application.Resources>

    <Style TargetType="syncfusion:GridCell" x:Key="nullCellStyle" >

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

    </Style>

</Application.Resources>


MainWindow.Xaml

<syncfusion:SfDataGrid x:Name="dataGrid"  ItemsSource="{Binding Orders}"

                        CellStyleSelector="{StaticResource styleSelector}"

                        AllowFiltering="True"

                        ShowGroupDropArea="True"

                        AutoGenerateColumns="True"

                        >


public class CellStyleSelector : StyleSelector

    {

        public override Style SelectStyle(object item, DependencyObject container)

        {

            var record = item as OrderInfo;

            var gridCell = container as GridCell;

            if (gridCell.ColumnBase.GridColumn.MappingName == "OrderID")

            {

                if (record.OrderID % 2 == 0)

                    return App.Current.Resources["nullCellStyle"] as Style;

            }

 

            return base.SelectStyle(item, container);

        }

    }



Attachment: SyncfusionTests_c30a39e8.zip

Marked as answer
Loader.
Up arrow icon