How to detect light or dark colour mode #18002
Closed
SimonORorke
started this conversation in
General
Replies: 2 comments 1 reply
-
I believe you can use one of these: Avalonia/src/Avalonia.Controls/Application.cs Lines 93 to 102 in 230e4fd But I have not tried it. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Basically repeating a comment I somehow accidentally deleted. private void DataGridOnLoadingRow(object? sender, DataGridRowEventArgs e) {
if (ActualThemeVariant == ThemeVariant.Dark) {
// These colours look good in Dark colour mode
e.Row.Foreground = controlViewModel.ColourId switch {
ColourId.Green => Brushes.Chartreuse,
ColourId.Orange => Brushes.DarkOrange,
ColourId.Red => Brushes.Red,
ColourId.Yellow => Brushes.Yellow,
_ => Brushes.White
};
} else { // ThemeVariant.Light
// These colours look good in Light colour mode
e.Row.Foreground = controlViewModel.ColourId switch {
ColourId.Green => Brushes.ForestGreen,
ColourId.Orange => Brushes.DarkOrange,
ColourId.Red => Brushes.Red,
ColourId.Yellow => Brushes.DarkGoldenrod,
_ => Brushes.Black
};
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How can a desktop application that uses a light/dark colour mode-sensitive Fluent theme find out the operating system's colour mode?
Usage example. I want to colour-code the text in each data row of a DataGrid depending on the value of a property of the row's corresponding view model. Given that the row background colour will be determined by the colour mode , some colour variants look good in dark mode but not light mode and vice versa.
Beta Was this translation helpful? Give feedback.
All reactions