I wanna create a pivot table in the user interface in a WPF with MVVM application. So the number of columns are not static.
I have found that I can programmatically add columns from the code behind file (as shown in below code snippets).
myDataGrid.Columns.Add(column );
But I don't wanna use the code behind file. I wanna do this with MVVM (from the view model). Can anyone give me a solution for this?
I found the solution.
The Answer is simple.
DataTable
in the view modelprogrammatically
within aforeach
loop)ItemsSource
property of the datagrid. (Make sure that theAutoGeneratedColumns=True
)My
View Model
I have assinged
dummy data
in the constructorMy
view