Resizing Header of DataGrid in WPF
I'm supposed to make some small graphical changes in WPF which I am unfamiliar with. There is this code in the xaml
<DataGrid x:Name="dtGridReads" AutoGenerateColumns="False"
VirtualizingStackPanel.IsVi开发者_StackOverflow社区rtualizing="True"
VirtualizingStackPanel.VirtualizationMode ="Standard"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
ScrollViewer.IsDeferredScrollingEnabled="True"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
ItemsSource ="{Binding}" Block.TextAlignment="Center"
AlternatingRowBackground="LightGoldenrodYellow" RowBackground="White"
CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
GridLinesVisibility="None" Style="{StaticResource ConcensusDataGridStyle}">
</DataGrid>
In the .cs file, I found I can change the fontSize for the data. However, I cannot seem to find where/how I would make the header font smaller. I'm trying to save real estate and shrink the DataGrid, but I can't find where to make the columns smaller, and text for the header in that first row smaller. Thanks.
Edit: Ok I found I can just change the FontSize in the DataGrid.
<DataGrid.ColumnHeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="FontSize" Value="10"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGridTextColumn.HeaderStyle>
<Style
TargetType="DataGridColumnHeader">
<Setter
Property="Background"
Value="SteelBlue"
/>
<Setter
Property="HorizontalContentAlignment"
Value="Center"
/>
<Setter Property="FontSize" Value="17"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</DataGridTextColumn.HeaderStyle>
精彩评论