I am trying to test animation in XAML. My intension was to make a font-size pulse (increase and decrease forever). But when I type in the code below, Visual studio does not recognize the class DoubleAnimation
. What am I doing wrong?
<Window x:Class="testingAnimation.MainWindow"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBlock Text="HELLO">
<TextBlock.FontSize>
<DoubleAnimation />
</TextBlock.FontSize>
</TextBlock>
</StackPanel>
</Window>
You need to declare a Storyboard
and start it upon load:
<TextBlock x:Name="Text" Text="Hello!!">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Duration="00:00:01" RepeatBehavior="Forever" AutoReverse="True">
<DoubleAnimation From="10" To="20" Storyboard.TargetName="Text" Storyboard.TargetProperty="FontSize"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
You need to use Storyboard
for running animation -
<TextBlock x:Name="textBlock" Text="HELLO">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever" AutoReverse="True">
<DoubleAnimation Storyboard.TargetName="textBlock"
Storyboard.TargetProperty="FontSize"
From="10" To="30"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
To learn more about animations follow this link here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With