How can i add a transition when changing style of a wpf tool?

61 Views Asked by At

I am designing an app in C# using WPF. I want to add a hover effect. When the user hovers on the button I want to increase its left border thickness. I did it by using the following method. But I want to add a transition of 1 second. I am stuck with it!!

        {
            
                btn1.BorderThickness = new Thickness(10, 1, 1, 1);
            
           } 
        ```
1

There are 1 best solutions below

2
Clemens On

You may animate a Thickness by a ThicknessAnimation.

btn1.BeginAnimation(
    Button.BorderThicknessProperty,
    new ThicknessAnimation(new Thickness(10, 1, 1, 1), TimeSpan.FromSeconds(1)));