I want to color the cells of my datagrid on dynamic conditions, and for now I just want all the cells red just to try.
With this code I am having that the variable "Row" is null. After reading numerous posts, I concluded that it is because the VirtualizingStackPanel.IsVirtualizingProperty is set to true to enhance performance. I understand that I need to turn this property off in the DataGrid "table" but for now with no success.
table.SetValue( VirtualizingStackPanel.IsVirtualizingProperty , false );
            table.ItemsSource = dt.DefaultView;
            for ( int r = 1 ; r < dt.Rows.Count ; r++ ) {
                for ( int c = 1 ; c < dt.Columns.Count ; c++ ) {
                    App.func.dmessage( "table.ItemContainerGenerator.Items.Count:" + table.ItemContainerGenerator.Items.Count );
                    DataGridRow Row = table.ItemContainerGenerator.ContainerFromIndex( r ) as DataGridRow;
                    DataGridCell cell = table.Columns[c].GetCellContent( Row ).Parent as DataGridCell;
                    //set background
                    cell.Background = Brushes.Red;
                }
            }
I have not seen any clear response to this question, so I'd really appreciate some clarity on how to set off this "VirtualizingStackPanel.IsVirtualizingProperty" property, so as to enable dynamic coloring of the table cells.
Context: the table is going to show electric node calculation voltages, and I want the users to set the upper and lower limits, and this cannot be done with XAML in design time.
 
    