C# – WPF – How to stop animation while mouse hovers over button

MiniBytes: In this article we are going to see, how to stop animation while mouse hovers over a button using C# code. This tutorial will be helpful for you to stop a storyboard animation while you hover your mouse over a image or button, which you can use in your C# WPF application. What i am narrating here is the code which was taken from the live projects which i am currently working on.

Microsoft didn’t give us any big GUI tools or external libraries that will auto generate the c# code for you. For designing the WPF application, you need to create your own code or you need to depend on the Google.

Lets wait for sometime till Microsoft generates some utility to do animation related works in WPF in addition to Visual Studio.

In this code, i am going to use the Storyboard to do the animation for a button. The button consists of no borders and colors, i have only included the image into the button.

By the way now we can see the code to start the animation while the window loads and stop the animation while we hover our mouse cursor on the button.

XAML Code:

However, in the above code, you can see event triggers for starting animation while you start the windows and button mouse enter and mouse leave event which has the trigger for doing animations.

You can use this code in your application especially for creating blinking effect on the button with mouse hover property.

Please leave the comments, if you have doubts and enjoy the code…:-)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − five =