Dear Support Team,
I have a DataGrid and bind Columns and Items dynamically with my ViewModel. The rendering is fine appart from the fact that the first column is not frozen (interestingly it is frozen when I change something in the XAML and hot-reload fires).
My second question ist how could I set a background color for the header row and the first column?
Thank you for your support.
XAML:
<sfGrid:SfDataGrid x:Name="dataGrid"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
BackgroundColor="LightSeaGreen"
AutoGenerateColumns="False"
AutoGenerateColumnsMode="None"
VerticalOverScrollMode="None"
ItemsSource="{Binding DataCollection, Mode=OneWay}"
Columns="{Binding GridColumns, Mode=OneWay}"
FrozenColumnsCount="1">
</sfGrid:SfDataGrid>
ViewModel:
Columns gridColumns;
ObservableCollection<SfTableDataRow> dataCollection;
public StatsPageViewModel(int pChapterId)
{
gridColumns = new Columns();
DataCollection = new ObservableCollection<SfTableDataRow>();
loadInitData(pChapterId);
}
public ObservableCollection<SfTableDataRow> DataCollection
{
get => dataCollection;
set
{
if (dataCollection == value) { return; }
dataCollection = value;
OnPropertyChanged(nameof(DataCollection));
}
}
public Columns GridColumns
{
get => gridColumns;
set
{
if (gridColumns == value) { return; }
gridColumns = value;
OnPropertyChanged(nameof(GridColumns));
}
}
private async void loadInitData(int pChapterId)
{
gridColumns.Add(new GridTextColumn() { MappingName = "data[0]",
HeaderText = "1960",
Width = 150,
HeaderTextAlignment = TextAlignment.Center,
TextAlignment = TextAlignment.Start });
gridColumns.Add(new GridTextColumn() { MappingName = "data[1]", HeaderText = "1961" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[2]", HeaderText = "1962" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[3]", HeaderText = "1963" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[4]", HeaderText = "1964" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[5]", HeaderText = "1965" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[6]", HeaderText = "1966" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[7]", HeaderText = "1967" });
gridColumns.Add(new GridTextColumn() { MappingName = "data[8]", HeaderText = "1968" });
SfTableDataRow list1 = new SfTableDataRow(new string[] { "11", "12", "13", "14", "15", "16", "17", "18", "19" });
SfTableDataRow list2 = new SfTableDataRow(new string[] { "21", "22", "23", "24", "25", "26", "27", "28", "29" });
SfTableDataRow list3 = new SfTableDataRow(new string[] { "31", "32", "33", "34", "35", "36", "37", "38", "39" });
SfTableDataRow list4 = new SfTableDataRow(new string[] { "41", "42", "43", "44", "45", "46", "47", "48", "49" });
dataCollection.Add(list1);
dataCollection.Add(list2);
dataCollection.Add(list3);
dataCollection.Add(list4);
OnPropertyChanged(nameof(GridColumns));
OnPropertyChanged(nameof(DataCollection));
}