WinUI3 Button XAML Template does not respect Foreground property after mouse passes over
See original GitHub issueDescribe the bug
In WInUI 3, create a Button with:
<Button Name="Undo1" Content="Undo." Background ="DarkSlateBlue" Foreground ="White"/>
On starting the app, the colors are correct, but after moving the mouse over the button, the text color will remain black rather that white as specified with Foreground property.
Steps to reproduce the bug
as above.
Note that the key issue is that the default template for Button (inside generic.xaml) does not have a templatebinding for Foreground, but includes Background. My reference for the template is: C:\Users.….nuget\packages\microsoft.windowsappsdk\1.0.3\lib\net5.0-windows10.0.18362.0\Microsoft.WinUI\Themes
The template contains:
<Setter Property="Background" Value="{ThemeResource ButtonBackground}" />
It should contain:
<Setter Property="Background" Value="{ThemeResource ButtonBackground}" />
<Setter Property="Foreground" Value="{ThemeResource ButtonForeground}" />
Expected behavior
Foreground color property should be reset to original color after the mouse has left the button zone. It will do that if the generic template is updated as suggested
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.0.3
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
Windows 10 (21H2): Build 19044
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:19 (5 by maintainers)
🎉
Microsoft.WindowsAppSDK.1.2.221209.1
has been released which fixes this issue.Handy links:
In this particular case, there is a template bind to the foreground property for the control. The foreground property is inherited by the ContentPresenter in the template. The PointerOver visual state is writing the foreground property and when going back to normal, the inhertited property is not going back to its original value. A workaround would be to explicitly set the foreground property on the ContentPresenter to a template binding instead of it getting inherited. That unfortunately needs a re-template. Testing a fix to WinUI3’s button template.
@michael-hawker There are other cases where the properties really need to be template bound instead of pointing to theme resources like you mention in your linked bug.