开发者

Resizing Header of DataGrid in WPF

开发者 https://www.devze.com 2023-03-29 22:33 出处:网络
I\'m supposed to make some small graphical changes in WPF which I am unfamiliar with.There is this code in the xaml

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号