Search code examples
c#wpfxamlmvvmdatagrid

Can`t change Foreground in DataGrid


I created DataGrid and put background to bi transparent. Now i want to set foreground to be Blue but it does`t want to change, always is black. I try to put Foreground="Blue" in all those places but never worked.

<DataGrid Background="Transparent" Foreground="Blue">
        <DataGrid.Columns Foreground="Blue">
            <DataGridTextColumn Foreground="Blue" Header="AAA"/>
            <DataGridTextColumn Foreground="Blue" Header="BBB"/>
            <DataGridTextColumn Foreground="Blue" Header="CCC"/>
            <DataGridTextColumn Foreground="Blue" Header="DDD"/>
        </DataGrid.Columns>
    </DataGrid>

I have this in my App.xaml so maybe there is some Themes that affect it but i don`t know how to overwrite it.

<ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

Solution

  • Fore some reason that don`t work in my project, there is some theme applied and overwrite wherever i put Foreground. What i did is put in DataGridTextColumn.Header Label and sat Foreground of Label and that worked. And i did it for every DataGridTextColumn in my DataGrid

    <DataGridTextColumn Binding="{Binding Name}" IsReadOnly="True" Width="Auto" >
                    <DataGridTextColumn.Header>
                        <Label Foreground="#FF0398E2" FontWeight="Bold" FontSize="16">Name</Label>
                    </DataGridTextColumn.Header>
                </DataGridTextColumn>