wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

When I click the Switch Theme button Twice,the theme Mica is not work

Open Smileher opened this issue 1 year ago • 5 comments

Describe the bug

When I click the Switch Theme button Twice,the theme Mica is not work

To Reproduce

Switch Dark Theme

Expected behavior

Mica

Screenshots

WeChat截图_20240202132206 WeChat截图_20240202132505 WeChat截图_20240202133049

OS version

Windows 11 23H2

.NET version

.NET FrameWork 4.8

WPF-UI NuGet version

3.0.0-preview.13

Additional context

No response

Smileher avatar Feb 02 '24 05:02 Smileher

Yeah, I see the same behaviour in 3.0.0. The Mica effect disappears when switching themes and is only applied again when the app is restarted.

johnvesalius avatar Feb 10 '24 15:02 johnvesalius

By the way, it doesn't work because there was a fix for another issue (ig), which disabled setting background to transparent. To get this to work, you need to set your window background to transparent (there's a public method for this, it only needs your window reference) You can fix that like so:

{
    ApplicationThemeManager.Apply(appTheme == ApplicationTheme.Light
                    ? ApplicationTheme.Dark
                    : ApplicationTheme.Light);
                    // where 'this' is your window instance, 
                    // winver is client OS build number, but it doesn't seem to break anything 
                    // when you remove background on the earlier versions 
                    // 22621 is windows build number which has mica support, though it may also work fine on some earlier ones
                if (winver > 22621) WindowBackdrop.RemoveBackground(this); 
}

Muniwedesu avatar May 21 '24 12:05 Muniwedesu

Hey @lepoco, @pomianowski - You have a couple of issues regarding the Mica effect and theme switching. Might be a few duplicates, but would you be so kind to look into these issues? I see a lot of comments in different repositories about them. Thanks!

Jay-o-Way avatar Jun 04 '24 13:06 Jay-o-Way

By the way, it doesn't work because there was a fix for another issue (ig), which disabled setting background to transparent. To get this to work, you need to set your window background to transparent (there's a public method for this, it only needs your window reference) You can fix that like so:

{
    ApplicationThemeManager.Apply(appTheme == ApplicationTheme.Light
                    ? ApplicationTheme.Dark
                    : ApplicationTheme.Light);
                    // where 'this' is your window instance, 
                    // winver is client OS build number, but it doesn't seem to break anything 
                    // when you remove background on the earlier versions 
                    // 22621 is windows build number which has mica support, though it may also work fine on some earlier ones
                if (winver > 22621) WindowBackdrop.RemoveBackground(this); 
}

Thank you ,I solved the problem. if (Environment.OSVersion.Version.Build > 22621) WindowBackdrop.RemoveBackground(this);

Smileher avatar Jun 05 '24 00:06 Smileher

Hey @lepoco, @pomianowski - You have a couple of issues regarding the Mica effect and theme switching. Might be a few duplicates, but would you be so kind to look into these issues? I see a lot of comments in different repositories about them. Thanks!

Now that I have initially solved this problem, when I change the theme, I need to determine whether the windows system version number is greater than 22621, and when it is greater, I need to remove the background, as mentioned above in @Muniwedesu

Smileher avatar Jun 05 '24 00:06 Smileher