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

[Bug] Accent Color and System Theme changes are not updated in Packaged WPF apps #175

Closed
ShankarBUS opened this issue Sep 17, 2020 · 10 comments
Labels
bug Something isn't working
Milestone

Comments

@ShankarBUS
Copy link
Contributor

ShankarBUS commented Sep 17, 2020

This could be similar to #143. But this is an entirely different case.

There was an attempt to remove the app.manifest requirement (previously a mandatory need to detect the OS version) in 2c27fba. Despite removing the app.manifest requirement the bug has occurred to me (and I do have app manifest)

When the app is executed as an unpackaged application, there are no problems with theme/accent changes.
But when the same app is executed as a packaged (MSIX) application, the accent-color/system-theme changes are not perceived by the packaged application.

I can assure that this bug doesn't happen when the app is unpackaged.

Workaround

I used Reflection to invoke this internal method This won't work see #175 (comment)

private void ListenToSystemColorChanges()
{
    Type ColorsHelperType = Type.GetType("ModernWpf.ColorsHelper, ModernWpf");
    PropertyInfo CurrentProperty = ColorsHelperType.GetProperty("Current", BindingFlags.Static | BindingFlags.Public);
    object colorsHelperInstance = CurrentProperty.GetValue(null);
    MethodInfo ListenToSystemColorChangesMethod = ColorsHelperType.GetMethod("ListenToSystemColorChanges",
        BindingFlags.Instance | BindingFlags.NonPublic);
    ListenToSystemColorChangesMethod.Invoke(colorsHelperInstance, null);
}
@ShankarBUS ShankarBUS changed the title [Bug] Accent Color and System Theme changes are not updating on Packaged WPF apps [Bug] Accent Color and System Theme changes are not updated in Packaged WPF apps Sep 17, 2020
@Kinnara Kinnara added the bug Something isn't working label Sep 25, 2020
@Kinnara Kinnara added this to the 0.9.3 milestone Sep 25, 2020
@Kinnara
Copy link
Owner

Kinnara commented Sep 25, 2020

Thanks for reporting. I'll look into it.

@Kinnara
Copy link
Owner

Kinnara commented Sep 29, 2020

The cause seems to be UISettings doesn't raise any events in a packaged app, although its methods and properties work fine. Does the workaround actually work? ListenToSystemColorChanges is already called inside the library and calling it again shouldn't make any difference.

@ShankarBUS
Copy link
Contributor Author

ShankarBUS commented Sep 30, 2020

Yep, calling ListenToSystemColorChanges actually works. I'm really confused now. I don't know how it worked 😅

How can UISettings not fire events? We already use some other WinRT APIs in our app and all of them (except one event) work fine.

You can clone the ModernFlyouts repo and check it out yourself.

I thought there were problems with the OSVersionHelper & packaging.
So I manually called the ListenToSystemColorChanges method myself. It worked however. Are you sure UISettings is the problem here?

@Kinnara
Copy link
Owner

Kinnara commented Sep 30, 2020

Yes, I'm fairly certain UISettings is the culprit, at least on Win10 2004. I tried ModernFlyouts and calling ListenToSystemColorChanges didn't seem to help—the settings window still didn't react to theme changes, for example.

@ShankarBUS
Copy link
Contributor Author

ShankarBUS commented Sep 30, 2020

Weird!!! There seems to be many issues with WinRT event triggering in .NET. Even an important API our app depends on (GSMTC) has this same problem. What should we do then?

How does the API work fine on unpackaged apps then?
It only happened while it was packaged. I thought the version checking didn't work but this seems to be out of our expertise, right?

@ShankarBUS
Copy link
Contributor Author

Yep! It's what you say 😅.

@ShankarBUS
Copy link
Contributor Author

I guess I will need to do another workaround

  • Hook to registry changes (use WMI event watcher to watch changes in the reg key - "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"'s value "AppsUseLightTheme" for theme changes)
  • Handle window messages (i.e. WM_DWMCOLORIZATIONCOLORCHANGED for accent colour changes)

I already have a method to watch "SystemUsesLightTheme" so it will be relatively easy for me to workaround this until you find a way to fix this. (Referrence : SystemTheme.cs)

@Kinnara
Copy link
Owner

Kinnara commented Oct 3, 2020

Fixed by 57b71b4.

@Kinnara Kinnara closed this as completed Oct 3, 2020
@ShankarBUS
Copy link
Contributor Author

Thanks @Kinnara!

@ShankarBUS
Copy link
Contributor Author

Hey @Kinnara, a suggestion

While committing a fix regarding a issue, you can use the Fix\Fixed\Fixes #{issue-no} {Issue Title} format to automatically close those issues while committing.

It saves me a lot of time. Would be helpful for you maintaining a repo efficiently

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