0

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);
            
           } 
        ```
  • In Wpf, it would make more sense to do the designs in the designer instead of the code-behind. You can use the Style property to style it the way you want when hovered over it. Here is a small example. Of course you should add something on top of it. https://stackoverflow.com/a/17259993/14875740 – Ozgur Saklanmaz May 24 '22 at 10:52
  • In addition, I recommend you to research the concepts of EventTrigger and Storyboard. – Ozgur Saklanmaz May 24 '22 at 10:55
  • I have basic concept of EventTriggers and StoryBoards. But they just change it from one state to another. i want to add a transition. Lets say i want to increase the font size from 14px to 30px. I want it to change in 2 sec. – Anosh Younas May 25 '22 at 20:59

1 Answers1

0

You may animate a Thickness by a ThicknessAnimation.

btn1.BeginAnimation(
    Button.BorderThicknessProperty,
    new ThicknessAnimation(new Thickness(10, 1, 1, 1), TimeSpan.FromSeconds(1)));
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • ThicknessAnimation is underlined in red. – Anosh Younas May 25 '22 at 20:57
  • And the IDE shows you an error message about a missing namespace. Click on the light bulb or press `Ctrl`+`.` - Visual Studio will suggest to add the missing `using` directive. – Clemens May 25 '22 at 21:33