In this blog we will see how the Mouse Enter
and Mouse Leave event works in WPF on Button Control. The mouse events are
present in all WPF control. In this blog I am explaining with respect to Button
control.
In XAML, I have created Mouse Enter and Mouse Leave on a button as you can see
in below snapshot highlighted mark.
Mouse Enter Event on Button
This is the code behind for Mouse enter event on button.
private
void button1_MouseEnter(object
sender, MouseEventArgs e)
{
button1.Content =
"Mouse Enter Event";
bird1.Visibility =
Visibility.Visible;
bird2.Visibility =
Visibility.Visible;
bird3.Visibility =
Visibility.Visible;
bird4.Visibility =
Visibility.Visible;
}
When Mouse enters the button all bird's in image control will get visible and
the content of button will change dynamically as you can see in below snapshot.
Mouse Leave Event on Button
This is the code behind for Mouse leave event on button.
private
void button1_MouseLeave(object
sender, MouseEventArgs e)
{
button1.Content =
"Mouse Leave Event";
bird1.Visibility =
Visibility.Hidden;
bird2.Visibility =
Visibility.Hidden;
bird3.Visibility =
Visibility.Hidden;
bird4.Visibility =
Visibility.Hidden;
}
When Mouse leave the button all bird's in image control will get hidden and the
content of button will change dynamically as you can see in below snapshot.
Summary
In this blog I have explained how the mouse event such as mouse enter and mouse
leave works on button, there are many other events in mouse you can just try it.
Thanks for reading this blog.