I'd like to display a table of items in WPF. In general that's not that hard, except that:
- I know, which columns I want to display only at runtime (user in a way defines them), and
- I'd like to avoid using codebehind: the XAML, where I want to display the table is inside a
DataTemplate
, which is inside anotherDataTemplate
etc. Introducing CodeBehind there will be problematic (though I will do that if I have no other options).
I though of using WPF's DataGrid
, which is smart enough to extract column names in runtime (depending on properties of collection items), but I know which columns I want to display only at runtime - I would have to create object with specific properties at runtime, what is also problematic (if possible).
Also, I don't really need to use specifically the DataGrid
, as this will be simple table of strings for preview only - it may be as well displayed, say, inside Grid with ItemsControl - I just need to provide a view with columns and rows.
So the questions are:
- How to customize displayed columns in DataGrid only from ViewModel (DataContext) and XAML?, or
- How to display tabular for preview data when columns are known at runtime only?