Light theme broken in last release
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;
}
}
Hi @MoodieG , can you please information about version of WinUI you are using?
The reproducible sample I shared is using a simple console application. However, the actual application is using Blazor Hybrid with WPF.
It does not crash on my configuration (Windows 10 22H2, WinUI 3 Desktop app as Admin (Manifest), Windows App SDK 1.7.250401001)
Hi @MoodieG , the above information is not sufficient for us to reproduce the issue, we need minimal repro project and its related details to investigate further
Hey @snigdha011997 , my original post shares the csproj file along with the program and environment details. What other details can I share?
This bug is related to using Windows.UI.Input.Preview.Injection APIs. Let me know if this is the wrong repo to post this issue. I posted it here because I found other users post similar issues regarding that here.
@MoodieG Since it didn't reproduced by others, can you please attach a complete repro project as zip?