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

Fix updating Windows resources at runtime #7830

Merged
merged 5 commits into from Jun 14, 2022
Merged

Fix updating Windows resources at runtime #7830

merged 5 commits into from Jun 14, 2022

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Jun 7, 2022

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

@Eilon Eilon added the area/controls 🎮 Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jun 8, 2022
@mattleibow mattleibow changed the title Fix windows things Fix updating Windows resources at runtime Jun 12, 2022
@mattleibow mattleibow marked this pull request as ready for review June 12, 2022 05:00
Comment on lines +328 to +340
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;
}
Copy link
Member Author

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.

@sjb-sjb
Copy link

sjb-sjb commented Feb 16, 2023

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.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/controls 🎮 Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/windows 🪟 t/bug Something isn't working
Projects
None yet
4 participants