UWP file explorer app
I am trying to use a ThemeResource in foreground for a DataGridTextColumn, but when opening the app it crashes, and I get this error:
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>
This is a legacy problem. If you need to use ThemeResouce
, you cannot directly assign values to DataGridTextColumn
, but you need to use CellStyle
:
<controls:DataGridTextColumn
...>
<controls:DataGridTextColumn.CellStyle>
<Style TargetType="controls:DataGridCell">
<Setter Property="Foreground" Value="{ThemeResource SystemColorGrayTextColor}" />
</Style>
</controls:DataGridTextColumn.CellStyle>
</controls:DataGridTextColumn>