我有一个 DataGrid,就 DataGrids 而言它非常简单。由于某种原因,标题与其余数据未对齐,如下面的屏幕截图所示:
我已经搜索了互联网,但似乎找不到解决方案。这是我的 DataGrid 代码:
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>
值得一提的是,当我单击其中一个组合框单元格时,标题会正确对齐。