One way to animate the BorderThickness of a Button in WPF is to use the DoubleAnimation and Storyboard classes. Here's an example code snippet:
<Button x:Name="MyButton" Content="Click Me">
<Button.Style>
<Style TargetType="Button">
<Setter Property="BorderThickness" Value="2"/>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="BorderThickness"
From="2" To="8" Duration="0:0:1"
AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
In this example, we first set the initial BorderThickness value of the button to 2. Then, we define a Storyboard that contains a DoubleAnimation which targets the BorderThickness property of the button. The animation starts from a value of 2 and goes up to 8, and has a duration of 1 second. We also set AutoReverse to True and RepeatBehavior to Forever, so the animation will oscillate between 2 and 8 pixels. Finally, we use an EventTrigger on the Loaded event to start the animation when the button is loaded in the window.
Asked: 2021-11-09 11:00:00 +0000
Seen: 7 times
Last updated: Jul 23 '22