Welcome Guest.


WPF modifies the background and border of the mouse floating on the button to be transparent

Asked by: Cynthia 343 views IT September 20, 2018

When the mouse is not on the button

When the mouse hovers over the button

I want the border and background to be transparent and then the font color is changed to black.

I have been working for 3 hours and haven't figured out QAQ

1 Answers

  1. +7Votes  

    There are two ways, events or styles

    to give you the code for an event


    <Button x:Name="Btn" Content="Button" HorizontalAlignment="Left" Height="47" Margin="81,104,0,0" VerticalAlignment="Top" Width="124" BorderThickness="0" Background= "Transparent" Foreground="GreenYellow" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave"/>


    private void UIElement_OnMouseEnter(object sender, MouseEventArgs e)
                         Btn.BorderThickness = new Thickness(1);
               Btn.BorderBrush = new SolidColorBrush(Colors.Black);
               Btn.Foreground = new SolidColorBrush(Colors.Black );;
               Btn.Background=new SolidColorBrush(Colors.Aqua);

           private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
               Btn.BorderThickness = new Thickness(0);
               Btn.BorderBrush = new SolidColorBrush(Colors.Transparent );;
               Btn.Foreground = new SolidColorBrush(Colors.GreenYellow);
               Btn.Background = new SolidColorBrush (Colors.Transparent);

    John- September 20, 2018 |