How to change the color of the onmoveover, onmouseleave button in wpf using triggers or any other events

I developed a WPF application with some buttons. Now I want to change the color of these buttons onmouseover, onmouseleave, onmouseenter using triggers or any other events. Any suggestion plz Thanks in advance.

+5
source share
1 answer

Inside the desired event, you can set the background color as follows:

// Change the background color of button1 to Blue
button1.Background = Brushes.Blue;

You can also set this in a trigger:

<!-- Button will change from Blue to Yellow on MouseOver -->
<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Blue" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Yellow" />
        </Trigger>
    </Style.Triggers>
</Style>

More information can be found in the Property Triggers section of this article.

+6
source

All Articles