-
Notifications
You must be signed in to change notification settings - Fork 335
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
RegNotifyChangeKeyValue is not working in WinUI3 app #4075
Comments
There are two questions, assuming that your project is created exactly how you described. In other words, assuming that the application is still packaged. First, if you remove the packaging, does the application work correctly? (Use The only way that I know of to detect the change between light and dark themes, outside of ColorValuesChanged, is to handle the WM_SETTINGSCHANGE message and look for the "ImmersiveColorSet" string. |
@DarranRowe Can't afford to make it unpackged. And that unvirtualized registry write capability requires Windows 10 18362, which is higher than what I want to target. |
Even if they are not what you want, it is just a testing step. Those checks are only there to see if it is the package getting in the way of the registry read. |
This seems weird as I do remember listening for changes on the exact particular registry key in a UWP app. |
2023-12-01.17-14-12.mp4It isn't a problem with Windows 11. |
packaged apps get registry virtualization by default. you can disable that with manifest settings. learn more here. |
@ChrisGuzak Any work around for Windows 10 17763? |
|
I can confirm that RegNotifyChangeKeyValue works fine after disabling registry virtualization via: <Package>
<Properties>
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
</Properties>
<Capabilities>
<rescap:Capability Name="unvirtualizedResources" />
</Capabilities>
</Package> in the appxmanifest.
If you need it badly, you could try to look into the VirtualDesktop API which has some change events. While researching I came across this: https://github.com/Grabacr07/VirtualDesktop It doesn't support 17763 because the COM GUIDs are regularly changing (kind of private API), but another project has the COM GUIDs for older Windows versions: So maybe(!) you'll be able to get the change event you need from this (I was looking for detecting a wallpaper change). |
@HO-COOH - if all you need is to monitor a theme change, why not use this? ((FrameworkElement)this.window.Content).ActualThemeChanged += this.Window_ThemeChanged; |
Ideally we want to provide a theme setting for user to able to override the system theme in app, so this is not an option. An independent theme listener is also necessary for fixing WinUI theme-related bugs (i.e fixing the incorrect title bar button color). |
Undocumented / private COM GUID is never an option for me. I need Microsoft to provide clearly documented, predictable behavior for achieving this, if they claim WASDK supports down to 17763. Oh wait, I was talking about |
Also WASDK doesn't claim to support all of its features down to 17763. Also 17763 is out of support, so there's nothing to expect from MS. Anyway, you asked for a workaround!
You wrote in your OP:
|
Why not? When overridden, you know your app's theme, why do you want to still know about desktop theme changes in this case?
Yes, I'm doing that based on ColorValuesChanged (not targeting 17763..) Monitoring WM_SETTINGSCHANGE is the only other way as @DarranRowe mentioned already. You can use WinUIEx or custom impl to monitor. It fires on theme change but not on wallpaper change. |
That's just a context for explaining the title I am asking. What if someone needs to monitor some other reg values and needs it to be packaged and also want to support 17763? There is no possible way until now, isn't it? So we either:
Also, I already implemented one using |
It's not that bad of an option. A theme change itself takes a while until it's fully completed, and when a user changes the theme they don't specifically whatch your title bar colors to be changed instantly, so polling the reg value like every 5 seconds should be perfectly sufficient. Have you ever watched ProcessMon from SysInternals for registry invocations? Quite often, you see hundreds of registry api calls within a single second, not just by apps but the OS itself. But as you can see, since they don't even manage to fix something blatantly trivial and widely visible on any WinUI3 app like the window titlebar control buttons - you cannot seriously expect that they'd do anything to make this work on an unsupported OS version.. 😜 |
Describe the bug
Following #4006, I tried to monitor
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
registry for light/dark theme listener, butRegNotifyChangeKeyValue
does not seem to work in a packaged winui3 app.The same code works in a console application project
Steps to reproduce the bug
MainWindow
constructorOutputDebugString
line. Toggle light/dark mode in system settings, the breakpoint is not hit.Bonus: If you use the commented code to monitor the value, it will reads the correct changes of the value, suggesting there is something wrong internally.
Expected behavior
No response
Screenshots
No response
NuGet package version
Windows App SDK 1.4.3: 1.4.231115000
Packaging type
Packaged (MSIX)
Windows version
Windows 10 version 1809 (17763, October 2018 Update)
IDE
Visual Studio 2022
Additional context
No response
The text was updated successfully, but these errors were encountered: