❔ WPF DataGrid RowStyle DataTrigger - Doesn't Keep Default Theme

Good morning/afternoon/evening all,

I am having some issues when setting a WPF DataGrid row background colour depending on a cell value.

I am using ModernWPF (https://github.com/Kinnara/ModernWpf) for a Light/Dark theme, and Controlzex (https://github.com/ControlzEx/ControlzEx) as a theme manager to switch between the light and dark theme depending on the users Windows theme setting.

My WPF DataGrid looks like this:

<DataGrid
    AutoGenerateColumns="False"
    ItemsSource="{Binding People}"
    CanUserAddRows="False">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding FirstName}" Value="Alice">
                    <Setter
                        Property="Background" Value="LightSkyBlue"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
    <DataGrid.Columns>
        <DataGridTextColumn
            Header="First Name"
            Binding="{Binding FirstName}" />
        <DataGridTextColumn
            Header="Last Name"
            Binding="{Binding LastName}" />
        <DataGridTextColumn
            Header="Full Name"
            Binding="{Binding FullName}" />
    </DataGrid.Columns>
</DataGrid>


The trigger does set a the background colour to
LightSkyBlue
when the person's first name is
Alice
, however, it then sets all the background colours of the other rows to be white. This isn't an issue when using the Light theme, but when a user is on a Dark theme then the White background matches the White foreground text.

Please see the attached comparison images where the Windows Light and Dark theme are used.

For further assistance, please find attached a copy of a small self contained example of the issue:
DataGridUI.zip
.

Please may someone help me in setting the row style, without affecting the default style.
GitHub
Modern styles and controls for your WPF applications - GitHub - Kinnara/ModernWpf: Modern styles and controls for your WPF applications
GitHub
Shared Controlz for WPF and ... more. Contribute to ControlzEx/ControlzEx development by creating an account on GitHub.
Was this page helpful?