Skip to content
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

High contrast detection in Theme Manager #3831

Closed
dsrivastavv opened this issue Jun 2, 2020 · 3 comments
Closed

High contrast detection in Theme Manager #3831

dsrivastavv opened this issue Jun 2, 2020 · 3 comments
Labels
Milestone

Comments

@dsrivastavv
Copy link

dsrivastavv commented Jun 2, 2020

I am working on a WPF project that involves changing theme dynamically at runtime based on Light/Dark/High Contrast mode and I am trying to use ThemeManager for it.

I have added four custom themes Light.Accent1, Dark.Accent1, HC.Light.Accent1 and HC.Dark.Accent1 as given below :

Light.Accent1

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:markupWithAssembly="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:system="clr-namespace:System;assembly=System.Runtime"
                    mc:Ignorable="options">

    <!--  Metadata  -->
    <system:String x:Key="Theme.Name">Light.Accent1</system:String>
    <system:String x:Key="Theme.Origin">MahAppsMetroThemesSample</system:String>
    <system:String x:Key="Theme.DisplayName">Accent1 (Light)</system:String>
    <system:String x:Key="Theme.BaseColorScheme">Light</system:String>
    <system:String x:Key="Theme.ColorScheme">Accent1</system:String>
    <Color x:Key="Theme.PrimaryAccentColor">Red</Color>
    <SolidColorBrush x:Key="SystemChromeLow" Color="Green" options:Freeze="True" />
</ResourceDictionary>

Dark.Accent1

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:markupWithAssembly="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:system="clr-namespace:System;assembly=System.Runtime"
                    mc:Ignorable="options">

    <!--  Metadata  -->
    <system:String x:Key="Theme.Name">Dark.Accent1</system:String>
    <system:String x:Key="Theme.Origin">MahAppsMetroThemesSample</system:String>
    <system:String x:Key="Theme.DisplayName">Accent1 (Dark)</system:String>
    <system:String x:Key="Theme.BaseColorScheme">Dark</system:String>
    <system:String x:Key="Theme.ColorScheme">Accent1</system:String>
    <Color x:Key="Theme.PrimaryAccentColor">Red</Color>
    <SolidColorBrush x:Key="SystemChromeLow" Color="Red" options:Freeze="True" />
</ResourceDictionary>

HC.Light.Accent1

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:markupWithAssembly="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:system="clr-namespace:System;assembly=System.Runtime"
                    mc:Ignorable="options">

    <!--  Metadata  -->
    <system:String x:Key="Theme.Name">Light.Accent1</system:String>
    <system:String x:Key="Theme.Origin">MahAppsMetroThemesSample</system:String>
    <system:String x:Key="Theme.DisplayName">Accent1 (Light)</system:String>
    <system:String x:Key="Theme.BaseColorScheme">Light</system:String>
    <system:String x:Key="Theme.ColorScheme">Accent1</system:String>
    <Color x:Key="Theme.PrimaryAccentColor">Red</Color>
    <system:Boolean x:Key="Theme.IsHighContrast">true</system:Boolean>
    <SolidColorBrush x:Key="SystemChromeLow" Color="Blue" options:Freeze="True" />
</ResourceDictionary>

HC.Dark.Accent1

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:markupWithAssembly="clr-namespace:MahApps.Metro.Markup;assembly=MahApps.Metro"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:system="clr-namespace:System;assembly=System.Runtime"
                    mc:Ignorable="options">

    <!--  Metadata  -->
    <system:String x:Key="Theme.Name">Dark.Accent1</system:String>
    <system:String x:Key="Theme.Origin">MahAppsMetroThemesSample</system:String>
    <system:String x:Key="Theme.DisplayName">Accent1 (Dark)</system:String>
    <system:String x:Key="Theme.BaseColorScheme">Dark</system:String>
    <system:String x:Key="Theme.ColorScheme">Accent1</system:String>
    <system:Boolean x:Key="Theme.IsHighContrast">true</system:Boolean>
    <Color x:Key="Theme.PrimaryAccentColor">Red</Color>
    <SolidColorBrush x:Key="SystemChromeLow" Color="Yellow" options:Freeze="True" />
</ResourceDictionary>

Code to auto sync theme with current system colors :

ThemeManager.Current.AddLibraryTheme(new LibraryTheme(
                                                         new Uri("pack://application:,,,/Light.Accent1.xaml"),
                                                         MahAppsLibraryThemeProvider.DefaultInstance));
ThemeManager.Current.AddLibraryTheme(new LibraryTheme(
                                                        new Uri("pack://application:,,,/Dark.Accent1.xaml"),
                                                        MahAppsLibraryThemeProvider.DefaultInstance));
ThemeManager.Current.AddLibraryTheme(new LibraryTheme(
                                                        new Uri("pack://application:,,,/HC.Dark.Accent1.xaml"),
                                                        MahAppsLibraryThemeProvider.DefaultInstance));
ThemeManager.Current.AddLibraryTheme(new LibraryTheme(
                                                        new Uri("pack://application:,,,/HC.Light.Accent1.xaml"),
                                                        MahAppsLibraryThemeProvider.DefaultInstance));
ThemeManager.Current.ChangeTheme(this, "Light.Accent1");
ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
ThemeManager.Current.SyncTheme(ThemeSyncMode.SyncWithAppMode);

The detection works fine in automatically syncing themes when system colors change from Light to Dark mode and vice versa. But turning on High contrast mode doesn't change to corresponding theme i.e HC.Light.Accent1 and HC.Dark.Accent1

Is there something I am missing?

@dsrivastavv
Copy link
Author

@punker76 Can you please help with this?

@punker76
Copy link
Member

punker76 commented Jul 2, 2020

@somil55 I moved this to ControlzEx #121 because the missing functionality is there.

@punker76
Copy link
Member

punker76 commented Jul 2, 2020

@somil55 This will be fixed with ControlzEx v4.3.1

@punker76 punker76 closed this as completed Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants