I’m trying to create a datagrid with auto generating columns.
Let’s say my Collection is a property named Articles of my viewmodel of type ObservableCollection<ArticleWrapper>.
I bind now the ItemsSource to this collection:
<wpf:DataGrid ItemsSource={Binding Articles} />
The class ArticleWrapper is like this:
[c#]
public class ArticleWrapper
{
public ArticleConfigurationSet ArticleConfigurationSet { get; set; }
public string Description { get; set; }
}
[vb.net]
Public Class ArticleWrapper
Public Property ArticleConfigurationSet As ArticleConfigurationSet
Public Property Description As String
End Class
The class ArticleConfigurationSet is like this:
[c#]
public class ArticleConfigurationSet
{
public string Key { get; set; }
public int Number { get; set; }
}
[vb.net]
Public Class ArticleConfigurationSet
Public Property Key As String
Public Property Number As Integer
End Class
The autogenerated columns look like this (please forget about the CustomEntries):

But now my problem: I want to bind the displayed data to my ArticleConfigurationSet property. But I cannot change my ItemsSource Binding, because the SelectedItem property of the datagrid must be of ArticleWrapper (for command handling).
The datagrid should also look like this:

Do you have any ideas how to do this?
why not set AutoGenrateColumns = false and create the gridcolumns and bindings dynamic in dependence of your ArticleConfigurationSet properties?
you dont have to change the view and you can do what you want.
edit: i mean you can iterate through your ArticleConfigurationSet properties(e.g. with reflection) and create the Gridcolumns and bindings by you.