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

[Regression] Form title bars are the wrong color (app with its own custom dark theming) #12014

Closed
rickbrew opened this issue Aug 30, 2024 · 5 comments · Fixed by #12104
Closed
Assignees
Labels
area-DarkMode Issues relating to Dark Mode feature 💥 regression-preview Regression from a preview release 🚧 work in progress Work that is current in progress
Milestone

Comments

@rickbrew
Copy link

.NET version

.NET 9.0.0-rc.1.24421.1 (downloaded at https://github.com/dotnet/sdk/blob/main/documentation/package-table.md)

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, it works fine in .NET 8. This only happens when I change the target framework to 9.

Issue description

I compiled my app (Paint.NET) for .NET 9-rc1. From my understanding this is the first build with the experimental dark mode functionality. Paint.NET has its own extensive Dark Mode theming with lots of custom painting, setting the right DWM attributes, and even sending a few not-really-documented-but-not-really-undocumented window messages to coerce certain controls to run in Dark Mode. For now I will not be using any of that, I am simply working on getting Paint.NET to boot up correctly in .NET 9 so that I can ship my own beta to the public and get more testing and validation.

This is how PDN should look when booting it up. This is running on .NET 8:
image

If I make one change, which is to target .NET 9 with this .NET 9-rc1 build, it looks like this:
image

Notice how the 4 floating window now have white title bars. This affects all child dialogs. The main window is not affected because I'm doing some very intensive (aka crazy) custom non-client painting in there.

I tracked this down to code in Control.SetVisibleCore(). It is calling a PrepareDarkMode method which unconditionally calls DwmSetWindowAttribute to set the DWMWA_USE_IMMERSIVE_DARK_MODE attribute -- even if none of the experimental dark theme flags are enabled!

PrepareDarkMode(HWND, Application.IsDarkModeEnabled);

I can almost work around this by overriding SetVisibleCore in the derived class, like so:

    protected override void SetVisibleCore(bool value)
    {
        base.SetVisibleCore(value);

        // This is my method where I handle all sorts of theming stuff, including calling 
        // `DwmSetWindowAttribute` to set the DWMWA_USE_IMMERSIVE_DARK_MODE 
        // attribute to the appropriate value based on my app's configuration
        RefreshGlass(false); 
    }

However, this causes a different problem: when a Form is first shown, you can see the title bar start out as white and then animate towards the correct black color. This does not happen on .NET 8. This is clearly happening because the DWMWA_USE_IMMERSIVE_DARK_MODE attribute is being set twice:

Desktop.2024.08.29.-.17.15.03.02.mp4

Paint.NET already manages this attribute, so I need WinForms to not manage it at all. I haven't enabled the experimental Dark Theme stuff, so I would expect literally no effect on any of my own custom theming, much of which will -- at least for now -- overlap with the experimental .NET dark theme stuff.

cc @KlausLoeffelmann

Steps to reproduce

I can provide access to a Paint.NET build and/or repository for reproducing this, if necessary.

@rickbrew rickbrew added the untriaged The team needs to look at this issue in the next triage label Aug 30, 2024
@elachlan elachlan added the area-DarkMode Issues relating to Dark Mode feature label Aug 30, 2024
@merriemcgaw merriemcgaw added help wanted Good issue for external contributors and removed untriaged The team needs to look at this issue in the next triage labels Sep 4, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the Help wanted milestone Sep 4, 2024
@rickbrew
Copy link
Author

rickbrew commented Sep 5, 2024

I'm not sure why this was tagged as help-wanted 🤔 This is @KlausLoeffelmann 's area, right? If he's on vacation or something then I can try to take a stab at it, but theming tends to be an area with a lot of delicate dependencies and I think Klaus would be able to figure it out a lot faster and a lot more safely than me.

@kirsan31
Copy link
Contributor

kirsan31 commented Sep 5, 2024

@rickbrew may be confusion here is due to topic subject? I think we need something like "[regression] .... "

@rickbrew
Copy link
Author

rickbrew commented Sep 8, 2024

I guess my point is that this isn't something where I'm trying to use the new Dark Mode experimental features. If that were the case, I'd expect it to have some bugs that could be fixed later.

This is a situation where I'm explicitly not using it, but it's still breaking my app in a way that prevents me from migrating to .NET 9.

@rickbrew rickbrew changed the title Form title bars are the wrong color (app with its own custom dark theming) [Regression] Form title bars are the wrong color (app with its own custom dark theming) Sep 8, 2024
@kirsan31
Copy link
Contributor

@KlausLoeffelmann @JeremyKuhne @elachlan @merriemcgaw @Tanya-Solyanik
Someone point this issue to the right (regression) direction pls🙏

@elachlan elachlan added the 💥 regression-preview Regression from a preview release label Sep 10, 2024
@JeremyKuhne JeremyKuhne removed the help wanted Good issue for external contributors label Sep 10, 2024
@JeremyKuhne
Copy link
Member

Sorry this got tagged incorrectly. Looking at it now.

@JeremyKuhne JeremyKuhne self-assigned this Sep 10, 2024
@JeremyKuhne JeremyKuhne modified the milestones: Help wanted, .NET 9.0, 9.0 RC2 Sep 10, 2024
JeremyKuhne added a commit to JeremyKuhne/winforms that referenced this issue Sep 10, 2024
…de a choice

This creates havoc for existing dark mode implementors.

Fixes dotnet#12014
@dotnet-policy-service dotnet-policy-service bot added the 🚧 work in progress Work that is current in progress label Sep 10, 2024
github-actions bot pushed a commit that referenced this issue Sep 10, 2024
…de a choice

This creates havoc for existing dark mode implementors.

Fixes #12014
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-DarkMode Issues relating to Dark Mode feature 💥 regression-preview Regression from a preview release 🚧 work in progress Work that is current in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants