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

[BUG] AppThemeColor does not work with setters, when using c# #2408

Open
2 tasks done
Axemasta opened this issue Dec 21, 2024 · 0 comments
Open
2 tasks done

[BUG] AppThemeColor does not work with setters, when using c# #2408

Axemasta opened this issue Dec 21, 2024 · 0 comments
Labels
bug Something isn't working unverified

Comments

@Axemasta
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

Originally I thought this was a maui bug, and I posted 26620.

It turns out whilst there is merit to that bug, using a hack to create a maui AppThemeBinding actually resolves the functionality problem (however it doesn't address the hole in maui's api...). My sample app used an AppThemeColor to set the normal / disabled states on an Editor.

When using AppThemeColor the behavior is not as expected, the correct colors don't apply and the visual state of the control is left broken...

Instead it applies correctly in xaml, but breaks the appearance when applied through code:

Enabled Disabled
Both editors whilst the controls are enabled Both editors whilst the controls are disabled

Expected Behavior

The following code:

VisualStateManager.SetVisualStateGroups(CodeEditor, [
    new VisualStateGroup()
    {
        Name = "CommonStates",
        States =
        {
            new VisualState()
            {
                Name = "Normal",
                Setters =
                {
                    new Setter()
                    {
                        Property = Editor.TextColorProperty,
                        Value = new AppThemeColor()
                        {
                            Light = Colors.Lime,
                            Dark = Colors.Gold,
                            Default =  Colors.Lime,
                        },
                        // Value = Colors.Gold,
                    }
                }
            },
            new VisualState()
            {
                Name = "Disabled",
                Setters =
                {
                    new Setter()
                    {
                        Property = Editor.TextColorProperty,
                        // Value = Color.FromArgb("#CCAC00"),
                        Value = new AppThemeColor()
                        {
                            Light = Colors.DarkGreen,
                            Dark = Color.FromArgb("#CCAC00"),
                            Default = Colors.DarkGreen,
                        }
                    }
                }
            }
        }
    }
]);

When applied to an Editor should apply a normal & disabled color that is theme aware:

Light Mode Enabled Light Mode Disabled Dark Mode Enabled Dark Mode Disabled
Light Mode Editor With Custom Enabled Text Color Light Mode Editor With Custom Disabled Text Color Dark Mode Editor With Custom Enabled Text Color Dark Mode Editor With Custom Disabled Text Color

Steps To Reproduce

Apply any code that uses a Setter to a color property and set the value to an AppThemeColor, see my reproduction for more!

Link to public reproduction project repository

https://github.com/Axemasta/MauiRepros/tree/main/src/VisualStateCodeRepro

Environment

- .NET MAUI CommunityToolkit:Any
- OS:All
- .NET MAUI:Any

Anything else?

No response

@Axemasta Axemasta added bug Something isn't working unverified labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

1 participant