i m using EventSetter inside Style tag in xaml and Handling MouseEnter event. But the problem is that the mouse enter event is only visible for a moment and get disappeard after that...why is it so??why it is not persisting??
this is my xaml file in which i have define style
<Style x:Key="MouseOverHighlightStyle">
<EventSetter Event="Button.MouseEnter" Handler="element_MouseEnter" />
<Setter Property="Button.Padding" Value="5"/>
</Style>
and this is my .cs file where i m handling events
namespace testing2
{
partial class stt
{
private void element_MouseEnter(object sender, MouseEventArgs e)
{
((Button)sender).Background =
new SolidColorBrush(Colors.LightGoldenrodYellow);
}
}
The behaviour you seeing is because in default template of button, there is a trigger on
IsMouseOver
property where explicit color is set to value#FFBEE6FD
.Specifically the trigger is this:
But unfortunately if you have to change the value in that trigger you have to override entire ControlTemplate of button.
For your case it will be like this (with color
LightGoldenrodYellow
):