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
1385
Can't reset field layouts when DataSource changes
posted

We use data in XamDataGrid where the columns are only known at runtime, and so bind to an ObservableCollection<BindableDynamicDictionary> as found on:

https://stackoverflow.com/questions/14171098/binding-datagrid-to-observablecollectiondictionary

The fields are created by handling the FieldLayoutInitialized event.

In general, it works pretty well.  Sometimes, the data in the VM gets changed (new/removed/relabeled columns, etc.) and we need the grid to update.  To do that we are handling DataSourceChanged and in v16.x and before it would work if we called 'grid.DefaultFieldLayout.Fields.Clear()'.  Then FieldLayoutInitialized would fire and the new columns would be set.

Now with v17.x (we're currently on v17.2), the DefaultFieldLayout.Fields.Clear() does remove the existing columns, but FieldLayoutInitialized is not called again and the grid contains no columns.

I'd like to fix this problem, but I'm also open to alternative solutions.