❔ 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:
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
GitHub - Kinnara/ModernWpf: Modern styles and controls for your WPF...
Modern styles and controls for your WPF applications - GitHub - Kinnara/ModernWpf: Modern styles and controls for your WPF applications
GitHub
GitHub - ControlzEx/ControlzEx: Shared Controlz for WPF and ... more
Shared Controlz for WPF and ... more. Contribute to ControlzEx/ControlzEx development by creating an account on GitHub.
8 Replies
Of course if my way of doing this is wrong then I would like to know too.
What if you try
BasedOn
?
eg. <Style TargetType="DataGridRow" BasedOn="{StaticResource DefaultDataGridRowStyle}">
^ beat me to it
I believe I tried the 'BasedOn' attribute to no avail
Oh my days, I was setting the based on to just 'DataGridRow'
This works exactly as I need it to.
How did you know which static resource name to use?
I searched the repo for
DataGridRow
and found the style.Ahh, I may have to do some digging around for other areas of my application. Thank you very much to both of you for looking into this.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.