benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.7k stars 143 forks source link

Get ForegroundBrush of not currently loaded theme #146

Closed jgh07 closed 3 years ago

jgh07 commented 3 years ago

Is there a way to get the ForegroundBrush of the not currently loaded theme (would be black in dark mode and white in light mode) in Xaml?

benruehl commented 3 years ago

You could try to load the correct ResourceDictionary and get the brush from it.

Something like this:

var colorScheme = new ResourceDictionary();
colorScheme.Source =
        new Uri("pack://application:,,,/AdonisUI;component/ColorSchemes/Light.xaml",
                UriKind.RelativeOrAbsolute);
var foreground = colorScheme[Brushes.ForegroundBrush] as Brush;

I did not test this code so it might not work exactly like this. (Source)

jgh07 commented 3 years ago

Is there a way to do this directly in XAML?

benruehl commented 3 years ago

You could wrap this code in some custom dependency property and use it in XAML.