0

I have a button that have the following code in the mouse enter event:

private void CloseB_MouseEnter(object sender, MouseEventArgs e) {
  CloseB.Background = Brushes.Red;
}

But when the mouse enters, the color of the button turns to a weird light-blue (almost white) color.

I already tried to set opacity to 1 and to set Background property as : new SolidColorBrush(Colors.Red);

It is located in a grid with Background color set to Black. And the original color of the button is also black.
I don't know what I am missing.

Note: variable CloseB is my button.

  • 1
    What you are seeing is the color when the button is mouse-over. The Background color you set is the color in normal state (without mouse-over). Is it Red after the mouse is moved out? – kennyzx Jul 04 '18 at 03:05
  • No, but only because I have another method that sets Background color to black again after the mouse leaves. – Vinícius Gabriel Jul 04 '18 at 03:09
  • Thank you. I would never thought of that. But now I have another problem to fix. – Vinícius Gabriel Jul 04 '18 at 03:10
  • 1
    Welcome. The button has many defined states, like disabled state, focused state, pressed state, each state has a different background color. To achieve your requirement, you need to learn how to edit the button's `ControlTemplate`. – kennyzx Jul 04 '18 at 03:17

2 Answers2

0

As @kennyzx mentioned, the color I saw was the default color of the button when mouse is over.

I fixed my problem removing my Backgroung property in the button xaml and adding a style based on : Change color of Button when Mouse is over

0

I think you are trying to use trigger. So first apply style in button definition and define trigger for your event.

ksdev
  • 56
  • 7