Not sure if this helps, but one approach that I have used in the past to separate the columns from my headings and present them separately.
Column definitions are defined in resources:
<UserControl.Resources> <ResourceDictionary> <GridViewColumnCollection x:Key="siColumnCollection"> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> ... </DataTemplate> </GridViewColumn.CellTemplate> <GridViewColumnHeader Content="Fish"/> </GridViewColumn> ...
Then the headers and the list are displayed separately, both refer to the same resource:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <GridViewHeaderRowPresenter Columns="{StaticResource siColumnCollection}"/> <ListView Grid.Row="1" ItemsSource="{Binding ViewModelList}"> <ListView.Resources> <DataTemplate x:Key="siNormalRowTemplate"> <GridViewRowPresenter Columns="{StaticResource siColumnCollection}"/> </DataTemplate> </ListView.Resources> </ListView> </Grid>
(I cannot promise that this XAML works exactly as it is written, but it gives you an idea).
The advantage of this scheme is that you can process the headers and the main part of the list separately. Therefore, if you want to insert some filler right after the GridViewHeaderRowPresenter, you can do it.
Change This solution works if you have a GridView, but unfortunately it does not work for a DataGrid. I do not see an equivalent way to separate the header and rows in the DataGrid, so this answer will only work if you are ready to change the DataGrid for the GridView. Sorry!
Stephen holt
source share