tags:

views:

1255

answers:

2

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.

+1  A: 

A simple Google search for "button mouseover wpf" yields this as its first result:

How do I change an item's appearance on mouseover in WPF?

Voting to close.

Matt Hamilton
Thanks for the reply. but we can change only the glow property. How to change the background too?
ibrahimkhan
The same pricinple applies. Instead of setting the "BitmapEffect" property, simply set the "Background" property.
Matt Hamilton
Denis Troller
Not a good reason to close a question.
siz
A: 

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.

Steve Dignan
A problem with this solution can be found in this question:http://stackoverflow.com/questions/1302756/why-is-the-buttons-background-changingThe same issue happened to me -- it would not seem to set the background.
JJO