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.
views:
1255answers:
2
+1
Q:
How to change the button color onmoveover,onmouseleave in wpf by using triggers or any other events.
+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
2009-06-01 11:32:05
Thanks for the reply. but we can change only the glow property. How to change the background too?
ibrahimkhan
2009-06-01 11:42:42
The same pricinple applies. Instead of setting the "BitmapEffect" property, simply set the "Background" property.
Matt Hamilton
2009-06-01 11:49:01
Denis Troller
2009-06-01 11:49:36
Not a good reason to close a question.
siz
2009-06-01 12:44:43
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
2009-06-01 13:32:52
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
2009-08-20 23:26:46