fix: protect NiceButton disabled colors from consumer implicit Label style#30
Conversation
…style A stock MAUI app template ships an implicit Label style whose CommonStates/Disabled visual state sets a grey TextColor. When the button is disabled, IsEnabled propagates to the inner icon/text labels and that inherited style attaches its visual states to them; visual-state setters outrank locally-set values, so they silently override the colors ApplyColors assigns — defeating both the 1.8.0 disabled-contrast fix and the DisabledTextColor bindable. Since virtually every MAUI app keeps the template's implicit styles, the contrast fix was ineffective in practice. Give each inner label its own element-level CommonStates group with empty Normal/Disabled states. An element-level visual-state group outranks a style-level one, so the inherited style's states never attach and ApplyColors keeps the final say.
There was a problem hiding this comment.
Pull request overview
This PR fixes a .NET MAUI styling precedence issue where an app template’s implicit Label style (via CommonStates/Disabled VSM setters) could silently override NiceButton’s intended disabled text/icon colors on its internal labels. The fix ensures NiceButton.ApplyColors remains the source of truth for disabled coloring without requiring any consumer action.
Changes:
- Adds element-level (empty)
CommonStatesvisual-state groups toNiceButton’s internal_iconLabeland_textLabelto block inherited style-level VSM setters. - Updates the README to document why disabled colors won’t be overridden by implicit
Labelstyles.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| README.md | Documents the disabled-color protection behavior and why it works. |
| NiceEntry/NiceButton.cs | Installs per-label element-level CommonStates VSM groups to neutralize inherited style-level disabled setters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewNo blocking issues found. Checked for bugs (MAUI VSM semantics), CLAUDE.md compliance, git history, prior-PR feedback, and code-comment consistency. Verified specifically:
Two take-it-or-leave-it nits: the parameter is typed Suggest a follow-up issue for the same treatment on other controls with internal MAUI elements (the stock template also ships Disabled VSM states on implicit |
Buggen (drabbar alla konsumenter)
Stock-MAUI-mallens implicita
Label-stil har enCommonStates/Disabled-VSM-setter som sätter gråTextColor. När knappen disablas propagerarIsEnabledned till de interna_textLabel/_iconLabel, och den ärvda stilens visual states attachar på dem. VSM-setters vinner över lokalt satta värden, så de skriver tyst över färgerna somApplyColorssätter — vilket besegrar både 1.8.0:s kontrastfix och den nyaDisabledTextColor-bindablen. Eftersom i princip varje MAUI-app behåller mallens implicita stilar var fixen verkningslös i praktiken.Fixen
Varje intern label får en egen element-nivå
CommonStates-grupp med tommaNormal/Disabled-states. Element-nivå-VSG slår stil-nivå-VSG i precedence, så mallens VSM kan aldrig attacha ochApplyColorsfår sista ordet — som designat. Kräver ingen åtgärd från konsumenten.Bygger rent (0 varningar/fel) för
net10.0-android+net10.0-ios. README uppdaterad.Inte med i denna PR
VisualStateGroupsskulle kräva att instansieraNiceButton, vilket behöver MAUI-runtime/Application-kontext. Det friståendeNiceEntry.Tests(länkad ren geometri, ingen MAUI-workload) kan inte göra det. Verifieras bäst på enhet/simulator.Disabled-VSM även på implicitaEntry/Editor-stilar. De Labeled*-kontrollernas interna MAUI-element hanterar inte disabled-färger explicit, så ingen kontrast-bugg uppstår där idag — men det är värt att hålla i minnet om sådana färger införs.