Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions NiceEntry/NiceButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public NiceButton()
FontSize = FontSize
};

NeutralizeInheritedVisualStates(_iconLabel);
NeutralizeInheritedVisualStates(_textLabel);

_contentHost = new Grid
{
HorizontalOptions = LayoutOptions.Center,
Expand Down Expand Up @@ -89,6 +92,21 @@ public NiceButton()
UpdateShadowView();
}

// Stock MAUI app templates ship an implicit Label style whose CommonStates/Disabled visual
// state sets a grey TextColor. When the button is disabled, IsEnabled propagates to the inner
// labels and that inherited style attaches its visual states to them — and visual-state setters
// outrank locally-set values, so they override the colors ApplyColors assigns (defeating both the
// disabled-contrast handling and DisabledTextColor). Giving each label its own element-level
// CommonStates group with empty states suppresses the inherited style's states (an element-level
// group outranks a style-level one), leaving ApplyColors with the final say.
private static void NeutralizeInheritedVisualStates(VisualElement label)
{
var common = new VisualStateGroup { Name = "CommonStates" };
common.States.Add(new VisualState { Name = "Normal" });
common.States.Add(new VisualState { Name = "Disabled" });
VisualStateManager.SetVisualStateGroups(label, new VisualStateGroupList { common });
}

/// <summary>True when the button must be measured square (Circle shape).</summary>
internal bool ForceSquare => ButtonShape == ButtonShape.Circle;

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ Override them when you need to match your app's own palette:

`null` (the default) means "use the built-in themed colors."

The disabled colors are applied directly to the button's internal labels and are protected from being overridden by your app's implicit `Label` style: `NiceButton` installs its own (empty) `CommonStates` visual-state group on those labels, so a stock template's `Disabled` visual state can't recolor them behind your back. You don't need to do anything for this to work.

### Enums and constants

- **`ButtonShape`** — `Rectangle`, `Rounded`, `Circle`
Expand Down
Loading