I've got a DataGrid, which is quite simple as far as DataGrids go. For some reason or other, the headers are not aligned with the rest of the data, as shown in the screenshot below:
I've searched the internet but cannot seem to find a solution for it. Here is my DataGrid code:
Grid>
<DataGrid Name="dgAttributes"
ItemsSource="{Binding itemsSource}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
CanUserSortColumns="False"
>
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" IsReadOnly="True" Binding="{Binding Field}" Header="Fields"/>
<DataGridComboBoxColumn Width="95" IsReadOnly="False" Header="Order" ItemsSource="{Binding Source={StaticResource SortOrderProvider}}" SelectedItemBinding="{Binding SortBy, Mode=TwoWay}"/>
<DataGridCheckBoxColumn Width="Auto" IsReadOnly="False" Binding="{Binding GroupBy}" Header="Group By"/>
<DataGridComboBoxColumn Width="85" IsReadOnly="False" Header="Aggregate" ItemsSource="{Binding Source={StaticResource AggregateProvider}}" SelectedItemBinding="{Binding AggregateBy, Mode=TwoWay}"/>
<DataGridTextColumn Width="Auto" IsReadOnly="False" Binding="{Binding Having}" Header="Having"/>
<DataGridTextColumn Width="Auto" IsReadOnly="False" Binding="{Binding DisplayOrder}" Header="Display Order"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
It may also be worth mentioning that when I click on one of the Combobox cells, the headers align themselves properly.
You are definitely having some style or something that is hiding the top left Select All
button of datagrid. Hence the columns are shifted to left a little.
Use this thread to get hold of that button in DataGrid.OnLoad
and check its Visibility
property.
Select All button WPF DataGrid
If its collpased/hidden, set the visibility to Visbility.Visible
. Or check its Width
being zero and set appropriate Width
.
Finally I defeated this problem Find the solution here.
Sorry I did not notice you are not overriding the DataGrid control template. I am afraid , you will have to define a control template in order to correct the DataGrid behavior.
PS : I have .NET Framework 4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With