Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
XamDataGrid Row Background Color Doesn't Refresh on Sort


I have a XamDataGrid that sets the background color depending on a status property within a model. The background is set correctly on start up but when I sort the columns using the built in sorter, the background color does not update. This causes some rows to have the wrong color and it does not correct itself until I scroll them out of view.

Here is my code below:


<grids:XamDataGrid x:Name="dataGrid" AutoGenerateColumns="False" Grid.Row="1" Grid.RowSpan="11" RowHeight="40" SelectionMode="SingleRow" SelectedItemsChanged="dataGrid_SelectedItemsChanged" SortDescriptionsChanged="ApplySort">
        <grids:TextColumn PropertyPath="Col1" Width="*" DataBound="StylizeRowColor" HeaderText="Col 1" />
        <grids:TextColumn PropertyPath="Col2" Width="3*" DataBound="StylizeRowColor" LineBreakMode="WordWrap" IsFilteringEnabled="True"/>
        <grids:TextColumn PropertyPath="Col3" Width="*" DataBound="StylizeRowColor" IsFilteringEnabled="True"/>
        <grids:NumericColumn PropertyPath="Col4" Width="*" HorizontalAlignment="Center" DataBound="StylizeRowColor" IsFilteringEnabled="True"/>

C# Code Behind
private List<DataModel> DataList;
private ColumnSortDescription DataSorter;
public SpreadsheetView()
    DataSorter = new ColumnSortDescription("Col1", Infragistics.Core.Controls.DataSource.ListSortDirection.Ascending);
    DataList = GetDataList();
    dataGrid.ItemsSource = DataList;
    dataGrid.SortDescriptions.PropertyChanged += ApplySorting;
    dataGrid.ReactsToSortChanges = true;

public List<SlotMachine> GetDataList()
    return DataService.GetData();

private void StylizeRowColor(object sender, DataBindingEventArgs args)
    if (args.CellInfo != null)
        var rowItem = args.CellInfo.RowItem;
        if (rowItem != null)
            DataModel item = rowItem as DataModel;

            switch (item.Status)
                case "InService":
                case "OutOfService":
                    args.CellInfo.Background = new Infragistics.XamarinForms.SolidColorBrush(Color.Red);

private void ApplySorting(object sender, PropertyChangedEventArgs e)
    if (dataGrid.ActualDataSource != null)

  • 33240
    Offline posted

    Hello Rafael,

    I have been investigating into the behavior you are seeing, and it sounds like there are some cells that are likely recycling themselves potentially into the same cell, and so when you sort, they will retain the same Background.

    In order to prevent this, I would recommend that you set the args.CellInfo.Background property in your default and “InService” cases in your StylizeRowColor event handler. You can set the args.CellInfo.Background back to a default background color to ensure that you prevent this behavior from happening.

    Please let me know if you have any other questions or concerns on this matter.