I have a DataGrid
(named OperatorDataGrid) and the row number is set via the LoadingRow
event:
private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
And the DataGrid
itself is bound to an ObservableCollection<FilterRow>
where FilterRow
as a property called Index
(not currently being used). The binding is done in the user control's constructor:
public AdvancedFilter()
{
InitializeComponent();
SetDefaults();
FilterRows.Add(new FilterRow());
OperatorDataGrid.ItemsSource = FilterRows;
}
What I can't figure out is how to bind the Row.Header
value back to the model as items can constantly be added/removed. The LoadingRow
method handles showing the number in the DataGrid
but I can't get that value back into the object bound to that specific row since the header is not a specific column that is defined in the <DataGrid.Columns>
section in the XAML. I did try the solution found here, however whenever I added a new row, the header cell would show Index is 0 for every row. Any suggestions would be appreciated.