-
-
Notifications
You must be signed in to change notification settings - Fork 910
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Setting application theme using ApplicationThemeManager does not work as I expected.
Works fine when using WPFUI 4.0.3 but not in 4.1.0
To Reproduce
I just copy pasted the code of the settings view from the WPFUI gallery
Expected behavior
A correct light theme
Screenshots
When first opening the app the light theme works fine:
Switching to dark theme works fine too:
But comming back to white theme does this :
OS version
windows 11
.NET version
.NET 8.0
WPF-UI NuGet version
4.1.0
Additional context
in app resources i used :
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Light" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
<helpers:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<helpers:ThemeToIndexConverter x:Key="ThemeToIndexConverter" />
<helpers:PaneDisplayModeToIndexConverter x:Key="PaneDisplayModeToIndexConverter" />
</ResourceDictionary>
</Application.Resources>
The settings viewmodel :
public partial class SettingsViewModel(INavigationService navigationService) : ViewModel
{
private bool _isInitialized = false;
[ObservableProperty]
private string _appVersion = string.Empty;
[ObservableProperty]
private ApplicationTheme _currentApplicationTheme = ApplicationTheme.Unknown;
[ObservableProperty]
private NavigationViewPaneDisplayMode _currentApplicationNavigationStyle =
NavigationViewPaneDisplayMode.Left;
public override void OnNavigatedTo()
{
if (!_isInitialized)
{
InitializeViewModel();
}
}
partial void OnCurrentApplicationThemeChanged(ApplicationTheme oldValue, ApplicationTheme newValue)
{
ApplicationThemeManager.Apply(newValue);
}
partial void OnCurrentApplicationNavigationStyleChanged(
NavigationViewPaneDisplayMode oldValue,
NavigationViewPaneDisplayMode newValue
)
{
_ = navigationService.SetPaneDisplayMode(newValue);
}
private void InitializeViewModel()
{
CurrentApplicationTheme = ApplicationThemeManager.GetAppTheme();
AppVersion = $"{GetAssemblyVersion()}";
ApplicationThemeManager.Changed += OnThemeChanged;
_isInitialized = true;
}
private void OnThemeChanged(ApplicationTheme currentApplicationTheme, Color systemAccent)
{
// Update the theme if it has been changed elsewhere than in the settings.
if (CurrentApplicationTheme != currentApplicationTheme)
{
CurrentApplicationTheme = currentApplicationTheme;
}
}
private static string GetAssemblyVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? string.Empty;
}
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working