fix(controls): Button foreground on pressed showing wrong color in dark mode#1733
Open
JyslaFancy wants to merge 1 commit into
Open
Conversation
…n ControlTemplate triggers Commit 4c711b6 (v4.2.1) changed the IsPressed and Disabled ControlTemplate triggers to set Foreground on the TemplatedParent instead of directly setting TextElement.Foreground on the ContentPresenter and ControlIcon elements. This relied on {TemplateBinding Foreground} to propagate the value, but TemplateBinding does not always properly reflect trigger-set values on the templated parent. In dark theme, this caused the button foreground to show the wrong color when pressed (falling back to the PressedForeground DP default of SystemColors.ControlTextBrush instead of the Style-set ButtonForegroundPressed resource). The fix restores the working approach from v4.2.0: directly targeting ContentPresenter and ControlIcon with TextElement.Foreground in both the IsPressed MultiTrigger and the IsEnabled (Disabled) Trigger. Fixes lepoco#1722
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1722
Root Cause
Commit 4c711b6 (released in v4.2.1) changed the IsPressed MultiTrigger and IsEnabled (Disabled) trigger in the ControlTemplate from directly setting on and to setting on the TemplatedParent (Button), relying on to propagate the value to the ContentPresenter elements.
However, WPF's does not always properly reflect trigger-set values on the templated parent. When a ControlTemplate trigger sets on the parent Button, the TemplateBinding on the ContentPresenter may fail to pick up this change, causing the ContentPresenter to use the default value () instead of the Style-setter value ().
In dark theme, this results in the button text showing the wrong (dark) color when pressed.
Fix
Restored the direct setters on and in both the IsPressed MultiTrigger and the IsEnabled (Disabled) trigger, matching the working approach from v4.2.0.