无法分配给 属性 'Microsoft.Toolkit.Uwp.UI.Controls.DataGridTextColumn.Foreground

Failed to assign to property 'Microsoft.Toolkit.Uwp.UI.Controls.DataGridTextColumn.Foreground

UWP 文件资源管理器应用程序

我正在尝试在 DataGridTextColumn 的前台使用 ThemeResource,但是当打开应用程序时它崩溃了,我收到了这个错误:

Failed to assign to property 'Microsoft.Toolkit.Uwp.UI.Controls.DataGridTextColumn.Foreground

App.xaml - ThemeDictionaries

<ResourceDictionary x:Key="Light">
    <SolidColorBrush x:Key="SystemColorGrayTextColor" Color="#99000000" />  
</ResourceDictionary>

<ResourceDictionary x:Key="Dark">
    <SolidColorBrush x:Key="SystemColorGrayTextColor" Color="#99FFFFFF" />
</ResourceDictionary>

DataGridTextColumn

<controls:DataGridTextColumn
    x:Name="sizeColumn"
    x:Uid="sizeColumn"
    Width="Auto"
    MinWidth="100"
    Binding="{Binding FileSize}"
    DisplayIndex="5"
    FontSize="14"
    Header="Size"
    IsReadOnly="True"
    Tag="Size" 
    Foreground="{ThemeResource SystemColorGrayTextColor}">
    <ToolTipService.ToolTip>
        <ToolTip Content="{Binding FolderTooltipText}" />
    </ToolTipService.ToolTip>
</controls:DataGridTextColumn>

这是一个遗留问题。如果需要使用ThemeResouce,则不能直接给DataGridTextColumn赋值,需要使用CellStyle:

<controls:DataGridTextColumn 
        ...>
    <controls:DataGridTextColumn.CellStyle>
        <Style TargetType="controls:DataGridCell">
            <Setter Property="Foreground" Value="{ThemeResource SystemColorGrayTextColor}" />
        </Style>
    </controls:DataGridTextColumn.CellStyle>
</controls:DataGridTextColumn>