Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Light theme broken in last release #1589

@TheoCvg

Description

@TheoCvg

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:
Image

Switching to dark theme works fine too:
Image

But comming back to white theme does this :
Image

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

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions