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
Fix updating Windows resources at runtime #7830
Conversation
internal static void RefreshThemeResources(this FrameworkElement nativeView) | ||
{ | ||
var previous = nativeView.RequestedTheme; | ||
|
||
// Workaround for https://github.com/dotnet/maui/issues/7820 | ||
nativeView.RequestedTheme = nativeView.ActualTheme switch | ||
{ | ||
ElementTheme.Dark => ElementTheme.Light, | ||
_ => ElementTheme.Dark | ||
}; | ||
|
||
nativeView.RequestedTheme = previous; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the real "fix" here and is basically a workaround with a still-workaround-but-not-totally fix coming in the core Windows App SDK.
It would be really handy to have an easy way to systematically convert resources into (efficient) properties. That way users could customize the control far more dynamically. It would be nice if this were built in or if there were a better/faster way to do it than the workaround. |
Description of Change
This PR is a workaround for the underlying issue that updating a resource that is applied with a
{ThemeResource}
does not take affect because it is actually a{StaticResource}
in disguise.There is a more real fix coming with https://dev.azure.com/microsoft/OS/_workitems/edit/39897009
But, for now the workaround is to trigger a "theme change" and that applies the new theme resources. The real fix is also going to do this, but without requiring changing properties.
Issues Fixed