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

Dark Theme Flickering To Light Theme Randomly #1267

Open
VanBuren77 opened this issue Nov 5, 2024 · 4 comments
Open

Dark Theme Flickering To Light Theme Randomly #1267

VanBuren77 opened this issue Nov 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@VanBuren77
Copy link

Describe the bug

Application Dark Theme flickering to Light Theme

To Reproduce

This is very difficult to reproduce, but effectively, I start the gallery sample application and switch to dark mode. After some time, or after triggering something on another widow, the application's theme will switch back to light mode. I am unable to consistently reproduce the bug, but after clicking on the "All samples" and mousing over the "Home" navigator it occurred. However, this doesn't happen consistently. And it seems to be triggered by other various events.

Expected behavior

I expect to simply click on dark mode and have the application remain on dark mode until I click on the button that triggers the SwitchThemes function.

Screenshots

No response

OS version

Windows 10 Enterprise

.NET version

8.0

WPF-UI NuGet version

main branch under the gallery:

4.0.0-rc.2

Additional context

Unfortunately this is very difficult to reproduce! I wish I could pinpoint the cause of what causes the theme flicker. Identifying the cause will likely lead to a clear fix. I suspect this is some resource failing to load.

@VanBuren77 VanBuren77 added the bug Something isn't working label Nov 5, 2024
@VanBuren77 VanBuren77 changed the title Bug title Dark Theme Flickering To Light Theme Randomly Nov 6, 2024
@VanBuren77
Copy link
Author

I captured some of the output below; you can see the system is attempting to set to light theme several times in a row without user input.

Microsoft.Hosting.Lifetime: Information: Application started. Press Ctrl+C to shut down.
Microsoft.Hosting.Lifetime: Information: Hosting environment: Production
Microsoft.Hosting.Lifetime: Information: Content root path: C:\Projects\GitHub\wpfui-main\src\Wpf.Ui.Gallery\bin\Debug\net8.0-windows10.0.22621.0
'Wpf.Ui.Gallery.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.Serialization.Formatters.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Wpf.Ui.Gallery.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.Intrinsics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DEBUG | a7c25928204b4fe39df57c2e42555e18 - Icons - Wpf.Ui.Gallery.Views.Pages.DesignGuidance.IconsPage | NAVIGATED
JOURNAL INDEX 2
JOURNAL LAST ELEMENT a7c25928204b4fe39df57c2e42555e18
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF1E9BFD
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF3DA9FF
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF5CB7FF
Wpf.Ui.Accent: INFO | Text on accent is DARK
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Dark (Dark): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Dark
'Wpf.Ui.Gallery.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DEBUG | 2b05bf46210448e7aa166f9316809265 - Colors - Wpf.Ui.Gallery.Views.Pages.DesignGuidance.ColorsPage | NAVIGATED
JOURNAL INDEX 3
JOURNAL LAST ELEMENT 2b05bf46210448e7aa166f9316809265
DEBUG | 8a95bf7ad7044bb08fcf3626ccaf8db3 - All samples - Wpf.Ui.Gallery.Views.Pages.AllControlsPage | NAVIGATED
JOURNAL INDEX 4
JOURNAL LAST ELEMENT 8a95bf7ad7044bb08fcf3626ccaf8db3
DEBUG | e5341f8df8ec4a7a9c6899a1e1f562c4 - Typography - Wpf.Ui.Gallery.Views.Pages.DesignGuidance.TypographyPage | NAVIGATED
JOURNAL INDEX 5
JOURNAL LAST ELEMENT e5341f8df8ec4a7a9c6899a1e1f562c4
DEBUG | e24256ecb8444d3b88aaa4dd7fffcc5b - Home - Wpf.Ui.Gallery.Views.Pages.DashboardPage | NAVIGATED
JOURNAL INDEX 6
JOURNAL LAST ELEMENT e24256ecb8444d3b88aaa4dd7fffcc5b
The thread '[Thread Destroyed]' (39112) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (10424) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (32740) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (37168) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (40764) has exited with code 0 (0x0).
DEBUG | 2b05bf46210448e7aa166f9316809265 - Colors - Wpf.Ui.Gallery.Views.Pages.DesignGuidance.ColorsPage | NAVIGATED
JOURNAL INDEX 7
JOURNAL LAST ELEMENT 2b05bf46210448e7aa166f9316809265
DEBUG | 8a95bf7ad7044bb08fcf3626ccaf8db3 - All samples - Wpf.Ui.Gallery.Views.Pages.AllControlsPage | NAVIGATED
JOURNAL INDEX 8
JOURNAL LAST ELEMENT 8a95bf7ad7044bb08fcf3626ccaf8db3
DEBUG | 2b05bf46210448e7aa166f9316809265 - Colors - Wpf.Ui.Gallery.Views.Pages.DesignGuidance.ColorsPage | NAVIGATED
JOURNAL INDEX 9
JOURNAL LAST ELEMENT 2b05bf46210448e7aa166f9316809265
The thread '[Thread Destroyed]' (7372) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (4276) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (40896) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (32836) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (38856) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (9060) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (23108) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (26744) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (33772) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (40704) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (40928) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (43996) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (18456) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (43268) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (38044) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (37224) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (35520) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (35956) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (36692) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (38072) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (38292) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (10256) has exited with code 0 (0x0).
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Light (Light): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Light
SystemThemeWatcher: INFO | 72044 (WPF UI Gallery) triggered the application theme change to Light.
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Light (Light): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Light
SystemThemeWatcher: INFO | 72044 (WPF UI Gallery) triggered the application theme change to Light.
The thread '[Thread Destroyed]' (33968) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (35300) has exited with code 0 (0x0).
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Light (Light): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Light
SystemThemeWatcher: INFO | 72044 (WPF UI Gallery) triggered the application theme change to Light.
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Light (Light): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Light
SystemThemeWatcher: INFO | 72044 (WPF UI Gallery) triggered the application theme change to Light.
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT
ApplicationThemeManager: INFO | Wpf.Ui.Appearance.ApplicationThemeManager tries to update theme to Light (Light): True
Wpf.Ui.TitleBar: INFO | Wpf.Ui.Controls.TitleBar received theme - Light
SystemThemeWatcher: INFO | 72044 (WPF UI Gallery) triggered the application theme change to Light.
Wpf.Ui.Accent: INFO | SystemAccentColor: #FF0078D7
Wpf.Ui.Accent: INFO | SystemAccentColorPrimary: #FF0071CA
Wpf.Ui.Accent: INFO | SystemAccentColorSecondary: #FF006ABE
Wpf.Ui.Accent: INFO | SystemAccentColorTertiary: #FF0063B1
Wpf.Ui.Accent: INFO | Text on accent is LIGHT

@VanBuren77
Copy link
Author

I set a breakpoint on the OnThemeChanged under the TitleBar in Wpf.Ui./ Wpf.Ui.Controls.TitleBar

It happens in this highest part of the call stack:

/// <summary>
/// Listens to system messages on the application windows.
/// </summary>
private static IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == (int)User32.WM.WININICHANGE)
    {
        UpdateObservedWindow(hWnd);
    }

    return IntPtr.Zero;
}

image

public static void ApplySystemTheme(bool updateAccent)
{
    SystemThemeManager.UpdateSystemThemeCache();

    SystemTheme systemTheme = GetSystemTheme();

    ApplicationTheme themeToSet = ApplicationTheme.Light;

    if (systemTheme is SystemTheme.Dark or SystemTheme.CapturedMotion or SystemTheme.Glow)
    {
        themeToSet = ApplicationTheme.Dark;
    }
    else if (
        systemTheme is SystemTheme.HC1 or SystemTheme.HC2 or SystemTheme.HCBlack or SystemTheme.HCWhite
    )
    {
        themeToSet = ApplicationTheme.HighContrast;
    }

    Apply(themeToSet, updateAccent: updateAccent);
}

I think it's auto trying to set to my system theme. 

@VanBuren77
Copy link
Author

I realize this may be a function of wanting the SystemThemeWatcher to watch for the system theme and then update. When this isn't made clear, this appears as a theme flickering bug. I think the solution would be to; if this is enabled, prevent the ability to switch to something other than the system theme. Otherwise, this is a hidden behavior.

@psi-pclement
Copy link

I have the same issue with WPF-UI 3.0.0 to 3.0.5.

One sure way to reproduce this issue is by locking your session (Win+L), and then log in back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants