我正在 WinUI 3 中使用 Windows 社区工具包中的 DataGrid。可用的信息非常少,我正在努力解决它。如何更改标题的字体大小?另外,这个DataGrid是虚拟化的吗?
CommunityToolkit.WinUI.UI.Controls。
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="ntk.DetailsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ntk"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<controls:DataGrid DataContext="MainViewModel" ItemsSource="{x:Bind ResultDatasets}"
AutoGenerateColumns="False"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
GridLinesVisibility="Horizontal"
IsReadOnly="False"
FrozenColumnCount="2"
IsTextScaleFactorEnabled="True"
SelectionMode="Single"
Background="White">
<controls:DataGrid.Resources>
<SolidColorBrush x:Key="GridLinesBrush" Color="LightGray" />
</controls:DataGrid.Resources>
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="ID" Binding="{Binding id}" Width="70"/>
<controls:DataGridTextColumn Header="data1" Binding="{Binding id}" Width="80"/>
<controls:DataGridTextColumn Header="data2" Binding="{Binding data2}" />
</controls:DataGrid.Columns>
</controls:DataGrid>
您可以修改
HeaderStyle
:
首先,添加
primitives
命名空间:
xmlns:primitives="using:CommunityToolkit.WinUI.UI.Controls.Primitives"
然后对于所有标题:
<controls:DataGrid>
<controls:DataGrid.ColumnHeaderStyle>
<Style TargetType="primitives:DataGridColumnHeader">
<Setter Property="FontSize" Value="32" />
</Style>
</controls:DataGrid.ColumnHeaderStyle>
</controls:DataGrid>
或对于每个标题:
<controls:DataGridTextColumn
Header="ID"
Binding="{Binding id}"
Width="70">
<toolkit:DataGridTextColumn.HeaderStyle>
<Style TargetType="primitives:DataGridColumnHeader">
<Setter Property="FontSize" Value="32" />
</Style>
</toolkit:DataGridTextColumn.HeaderStyle>
</controls:DataGridTextColumn>