Skip to content

Fix updating Windows resources at runtime#7830

Merged
hartez merged 5 commits intonet6.0from
dev/fix-win
Jun 14, 2022
Merged

Fix updating Windows resources at runtime#7830
hartez merged 5 commits intonet6.0from
dev/fix-win

Conversation

@mattleibow
Copy link
Copy Markdown
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 legacy-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
Copy Markdown
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
Copy Markdown

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
@samhouts samhouts added the fixed-in-6.0.408 Look for this fix in 6.0.408! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-6.0.408 Look for this fix in 6.0.408! legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/windows t/bug Something isn't working

Projects

None yet

5 participants