question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hovering over the Button with mouse, the button’s foreground changes unexpectedly

See original GitHub issue

Describe the bug Hovering over the Button with mouse, the button’s foreground changes unexpectedly

Steps to reproduce the bug

  1. Create a button in XAML and with Foreground like “Gray”
  2. Run and hover you mouse on it

Expected behavior Should not change the foreground color

Screenshots

GIF 8-18-2021 2-56-02 PM

Version Info

NuGet package version: [Microsoft.UI.Xaml 2.7.0-prerelease.210816001] [Microsoft.UI.Xaml 2.6.1] [Microsoft.UI.Xaml 2.6.2-prerelease.210811003]

Windows app type:

UWP Win32
Yes
Windows version Saw the problem?
Insider Build (xxxxx)
May 2021 Update (19043) Yes
October 2020 Update (19042)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context Example code:

<StackPanel>
            <Button Foreground="Gray" 
                    Width="100"
                    Content="Hello"/>
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
            <Button Foreground="Gray"
                    Width="100"
                    Content="Hello" />
</StackPanel>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eugenegffcommented, Oct 17, 2021

@ranjeshj @MikeHillberg and @jevansaks any ideas what might have gone wrong?

I determined what caused such problem in Version2 styles comparing to Version1 styles. ButtonForeground and ButtonForegroundPointerOver were different in Version1 and became the same in Version2. Tweaking Version2 ButtonForegroundPointerOver to be different than ButtonForeground fixes the issue too.

Seems that VisualStateManager somehow decides that it has no work to do if brushes are the same even when Foreground propagation is involved and work needs to be done.

Having this in mind, I think that “to add Foreground=”{TemplateBinding Foreground}" to the button’s ContentPresenter" is a good workaround, that should be immediately applied to the MUX, as underlying issue is in OS code, and MUX should support old OS versions too. Fix for Button and ToggleButton is in PR #6105, DropDownButton is affected too.

@StephenLPeters @ranjeshj @jevansaks @tashatitova FYI

Button_themeresources_v1.xaml

            <StaticResource x:Key="ButtonForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
            <StaticResource x:Key="ButtonForegroundPointerOver" ResourceKey="SystemControlHighlightBaseHighBrush" />

Button_themeresources.xaml

            <StaticResource x:Key="ButtonForeground" ResourceKey="TextFillColorPrimaryBrush" />
            <StaticResource x:Key="ButtonForegroundPointerOver" ResourceKey="TextFillColorPrimaryBrush" />
0reactions
github-actions[bot]commented, Jul 29, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you change Background for a Button MouseOver ...
By setting the background of the grid to "Transparent", it adds a hittest, which means that if the mouse is anywhere over the...
Read more >
UWP app Button customization - Microsoft Q&A
Open the Document Outline Window in your VS and find the target button control. Right-click on the button, go to Edit Template ->...
Read more >
Active, Hover, and Focus States for Designers | by Corak
So the active state is not the selected state. To see it more clearly, hover over the button with the mouse and click...
Read more >
While-hovering + On-click interactions don't work well ...
The answer buttons have a hover state and a click (or mouse down) state to render as selected before moving on. These work...
Read more >
Wpf button hover color. Please Help my code is. I am creating a
Create a mouse hover effect in buttons using XAML. Set the button's FlatStyle to Flat. ... How to change foreground color of button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found