New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System Theme Support #3695
Comments
Would be interesting to see how this would pan out with Linux and macOS :) |
Just a few notes: The intention of this is to get the environments' colour scheme, map those colours to ResourceKeys for use with styling the controls. This is not intended to style the controls to look like the target system, that would be a massive undertaking and one I am not prepared to do in the foreseeable future. The fact the the Avalonia controls look similar to those in Windows 10 (UWP) is most likely coincidental, the fact they are simple (flat) makes theme'n them somewhat trivial. I will fire up my Ubuntu VM and see what I can find out from the OS about and getting theme/color information, that said Linux offers many different desktop environments. |
@wdcossey See https://stackoverflow.com/a/16286405/2231814 for more details. |
what about s/t like this https://stackoverflow.com/a/56415144 |
Those:
The described approach also doesn't work with complex GTK themes, since GTK themes use full CSS selector syntax with stuff like n-th child: https://developer.gnome.org/gtk3/stable/chap-css-overview.html |
@kekekeks don't think there is any intention to style avalonia controls exactly like system ones just grab some color to match theme a bit if possible, it's far from ideal but no other way |
We might end up with black text on black background because we've failed to understand the theme. |
The only viable approach I can think of is to get the theme name from the system and ship pre-configured colors for the most popular ones. If a particular machine uses a theme outside of the pre-configured list, we should attempt to match one based on the current DE and distro name. For power users, we could look for an Avalonia-specific configuration file from somewhere in |
@kekekeks I suspected that might have been the case with at least one or more operating systems, hence why this is currently focused on Windows. The implementation I am working on focuses around
|
I will also add Default and Custom options to
|
To be honest this should be optional and live in a separate repo. There are plans to support control themes. I don't understand the benefit of a ThemeResource. What is different to a regular DynamicResource? Most of my WPF projects just use DynamicResources for changing the look of the application. |
I don't know if same can be applied to GTK, but in KDE there is a C++ library which allows getting current color scheme - dark/light theme is merely background color value there. |
I am currently working on an alternative solution to the theming in Avalonia. First I have to update the controls to support more colour/brush properties/options as the current implementation is a bit sparse (i.e ButtonBorderBrushNormal/Focused/Hover/etc) Whilst I haven't dropped my idea of adding some system theme (colour) support it will be an addition to what I am currently working on. |
Would be great to see
A dynamic resource defers value lookup until it's required. It also automatically re-evaluates the value when the resource dictionary is changed behind the scenes. A ThemeResource looks the value up right away -- but automatically changes to a different resource dictionary and looks the value up again when the theme changes. A DynamicResource cannot process these types of system theme change notifications and automatically change the UI. Some code must be swapping out the resource dictionaries to trigger the updates.
|
DynamicResource can replace ThemeResource, so it does in Avalonia, although with overhead (as you described, ThemeResource is way more lightweight). |
Hey everyone,
I am working on adding system theme support to Avalonia, currently this is only supported for Windows 10 (and 8.1).
Once I have finished the Windows 10 support I'll add further support for legacy Windows products and then move onto other operating systems.
It's still early days but I'll try update you while I make progress (perhaps on my forked branch w/o clogging up the issues here).
ThemeResourceProvider
OS Registration
ThemeResource Bindings
Setup Default Theme (Currently Light/Dark)
See RequestedTheme property
Usage (Note resource keys are not finalised)
Override Application Theme
The text was updated successfully, but these errors were encountered: