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 :
<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>
<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>
<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>
<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?
@punker76 Can you please help with this?
@somil55 I moved this to ControlzEx #121 because the missing functionality is there.
@somil55 This will be fixed with ControlzEx v4.3.1
Most helpful comment
@somil55 This will be fixed with ControlzEx v4.3.1