简体   繁体   中英

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.IsVirtualizing="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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM