Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 919
ibrahimkhan Avatar asked Jun 01 '09 11:06

ibrahimkhan


1 Answers

Inside the desired event, you can set the background color like this...

// 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>

For even more details, check out the Property Triggers section of this article.

like image 55
Steve Dignan Avatar answered Oct 07 '22 13:10

Steve Dignan