Binding DataGrid to DataTable. DataGrid's ItemSource is null on first load. - WPF
I'm trying to bind a DataGrid to a DataTable located in my viewmodel. The columns are dynamic hence why I'm binding to a DataTable and adding the columns and rows in the viewmodel. The relevant VM code looks like:
Now the viewmodel is created before the view, and the view's datacontext is set to the viewmodel when the view is created.
The xaml for the DataGrid is:
There are certain columns I need to hide based on a list of strings in the VM. So I checked in both the View's Loaded event and the DataGrid's Loaded event, and in both cases the ItemSource is null, so I can't access the columns to hide them. Why would it be null if it is bound to the DataTable in the vm?
Now the viewmodel is created before the view, and the view's datacontext is set to the viewmodel when the view is created.
The xaml for the DataGrid is:
There are certain columns I need to hide based on a list of strings in the VM. So I checked in both the View's Loaded event and the DataGrid's Loaded event, and in both cases the ItemSource is null, so I can't access the columns to hide them. Why would it be null if it is bound to the DataTable in the vm?
