WPF C# DataGrid 设置字体大小 - 详细教程
可以通过设置 DataGrid 的 CellStyle 来设置字体大小,示例代码如下:
<DataGrid>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="FontSize" Value="16"/>
</Style>
</DataGrid.CellStyle>
</DataGrid>
上述代码将 DataGrid 中所有单元格的字体大小设置为 16。
如果只想设置某一列的字体大小,可以通过设置 DataGridTemplateColumn 的 CellStyle 来实现,示例代码如下:
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontSize="16"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
上述代码将 DataGrid 中 Name 列的字体大小设置为 16,并将单元格的水平对齐方式设置为居中。
原文地址: https://www.cveoy.top/t/topic/kfR1 著作权归作者所有。请勿转载和采集!