When attempting to Insert a new field at index 0 on XamDataGrid.FieldLayout.First().Fields, it consistently appears visually in the second column, despite it properly being assigned the 0th index. In fact, .Fields.Insert(0, field) visually appears exactly the same as .Fields.Insert(1, field)
I am attempting to insert a new column to certain XamDataGrids via a DependencyProperty, which when set to True, calls an XamDataGrid_Loaded() event:
static void xamDataGrid_Loaded(object sender, RoutedEventArgs e)
{
var grid = sender as XamDataGrid;
var field = new UnboundField
Name = "MaxAlertSeverity",
Label = string.Empty,
Width = FieldLength.Auto,
Settings = new FieldSettings()
CellValuePresenterStyle = Application.Current.Resources["AlertIndicatorCellValuePresenter"] as Style,
AllowSummaries = false,
AllowRecordFiltering = false,
AllowFixing = AllowFieldFixing.No
}
};
var fieldLayout = grid.FieldLayouts.First();
var bkn = fieldLayout.Fields.Where(f => f.Name == "BKN").First();
var bknPos = fieldLayout.Fields.IndexOf(bkn);
if (bknPos > 0)
fieldLayout.Fields.Insert(bknPos, field);
else
// weird hack to place caution indicators in first column
fieldLayout.Fields.Remove(bkn);
fieldLayout.Fields.Insert(0, field);
fieldLayout.Fields.Insert(1, bkn);
This behavior only occurs if I am trying to insert at index 0, at which point it still visually appears to the right of the first column. I attempted to “hack” it demonstrated on the else block above, but even removing and re-inserting the original first column despite re-inserting it at index 1 still kept the original column visually appearing first. In short, I would like my newly inserted column to appear just before the column with the name “BKN”, even if BKN is originally the first column.
Resolved via one of the plethora of obscure properties available on XamDataGrid:
grid.FieldLayoutSettings.AutoArrangePrimaryFieldReservation = AutoArrangePrimaryFieldReservation.None;