UWP XAML Button foreground color.

VoyTec 671 Reputation points
2022-11-14T17:48:06.01+00:00

OLD:
I changed the color of the foreground (text) color of a button, but when in app i hover over the button it switches to black (default). I tried to change focus color but with no success. Is there a way to make white text permanent for a default vs2022 button?

UPDATED:
<Button x:Name="Apartment_no_1" Content="+ dodaj mieszkanie +" Margin="250,150,0,0" VerticalAlignment="Top" Height="100" Width="178" Background="SkyBlue" Foreground="White" FontFamily="Segoe UI Light" FontSize="16" Click="Apartment_no_1_C" TabIndex="1"/>

I even tried to change Focus color with no result.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 83,096 Reputation points
    2022-11-14T19:40:11.107+00:00

    You can change resources, like ButtonForegroundPointerOver, in App.xaml

    For example, Yellow text on Blue background :

      <Application.Resources>  
         
            <SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="Blue"/>  
            <SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="Yellow"/>  
    

    260237-button-buttonforegroundpointerover.gif

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Roy Li - MSFT 32,731 Reputation points Microsoft Vendor
    2022-11-17T06:36:47.157+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I changed the color of the foreground (text) color of a button, but when in app i hover over the button it switches to black (default). I tried to change focus color but with no success. Is there a way to make white text permanent for a default vs2022 button?

    @Castorix32 's answer is correctly. He overrides the default brush for pointer over of all the button in the application resources. His soultion will change the foreground color of all the buttons in the app when pointer over.

    I would like to share a similar solution for your requirement which you could try if you failed to use his soultion.

    1) Create a default button style for the target button.
    2) Find the VisualStateManager.VisualStateGroups parts of the ContentPresenter inside the template.
    3) Change the value for Foreground in the VisualState named PointerOver. In my test, I changed it to yellow.
    4) Add a VisualState named Focused, then add ObjectAnimationUsingKeyFrames to change the color when the button gets focused. In my test, I changed it to red.
    5) Apply the style for the target button.

    I failed to post the code in the answer. I added an attachment with the code that you could refer to. Please check the attachment and let me know if it works for you.

    261237-buttonstyle.txt

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments