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

ThemeVariantScope doesn't refresh resources on first change of RequestedThemeVariant #10201

Closed
amwx opened this issue Feb 3, 2023 · 4 comments · Fixed by #10149
Closed

ThemeVariantScope doesn't refresh resources on first change of RequestedThemeVariant #10201

amwx opened this issue Feb 3, 2023 · 4 comments · Fixed by #10149
Assignees
Labels

Comments

@amwx
Copy link
Contributor

amwx commented Feb 3, 2023

Describe the bug

In my FluentAvalonia sample app, I have an option to toggle the theme for controls without changing the entire app theme. With the new ThemeVariant stuff, I've added a ThemeVariantScope control into the page to keep this behavior. When the theme toggle is requested the first time on the ThemeVariantScope, it doesn't tell the resources to refresh, and requires multiple attempts to get it to apply.

Video: (hopefully the clicking comes across) It takes 3 clicks to get the theme change to apply and then it works normally

Media1.mp4
  • Version 11.0.999-cibuild0029462-beta
@amwx amwx added the bug label Feb 3, 2023
@maxkatz6
Copy link
Member

maxkatz6 commented Feb 3, 2023

Is it pushed to the branch? Theme switch works from the first change in the control catalog which makes it weird.
Only known issue so far was with popups inside of theme variant scope.

@amwx
Copy link
Contributor Author

amwx commented Feb 4, 2023

Is it pushed to the branch? Theme switch works from the first change in the control catalog which makes it weird. Only known issue so far was with popups inside of theme variant scope.

Not yet, I'm still cleaning up some of the old theme switch code but I'll try to push something out later this evening.

EDIT: Actually I can repro with this simple example in a new Avalonia project (with Avalonia.Themes.Fluent):

<Window>
    <ThemeVariantScope Name="ThemeScope">
		<Button Content="Click Me" />
	</ThemeVariantScope>
</Window>
var ts = this.FindControl<ThemeVariantScope>("ThemeScope");

KeyDown += (s, e) =>
{
    if (e.Key == Key.Space)
    {
        if (ts.ActualThemeVariant == ThemeVariant.Light)
        {
            ts.RequestedThemeVariant = ThemeVariant.Dark;
        }
        else
        {
            ts.RequestedThemeVariant = ThemeVariant.Light;
        }
    }
};

Edit again:
Adding NotifyChildResourcesChanged(new ResourcesChangedEventArgs()); after setting the RequestedThemeVariant gets it to apply on the first try, although this is on the window (since that's a protected method). Looking at the code, I can't find where the change of ActualThemeVariant triggers the resource invalidation (I don't see any property changed handlers for the property, except in TopLevel where it passes to PlatformImpl?.SetFrameThemeVariant)

@robloo
Copy link
Contributor

robloo commented Feb 7, 2023

There are a few instances I see where the theme variant isn't being applied correctly. For example, a popup isn't getting it set correctly. And even overlays that were hidden but then changed to visible keep the old theme variant. Doesnt relate exactly to this issue so just FYI. Seems to indicate invalidating is broken or the property isn't (re)applied on visibility changes.

@maxkatz6
Copy link
Member

@amwx found the issue #10345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants