Reputation: 2626
I have one Button Name Button1. I want to change this button font size in animation. So I wrote code in Window_Loaded function.
DoubleAnimation da = new DoubleAnimation(0, 25, new Duration(TimeSpan.FromSeconds(3)));
//da.TargetPropertyType = "Width";
da.RepeatBehavior = RepeatBehavior.Forever;
button1.BeginAnimation(Button.FontSizeProperty, da);
But I have got an Error-
Cannot animate the 'FontSize' property on a 'System.Windows.Controls.Button' using a 'System.Windows.Media.Animation.DoubleAnimation'. For details see the inner exception.
1) How to Animate Button Font Size? 2) What are the properties I have to Animate in Button?
Upvotes: 3
Views: 3917
Reputation: 17145
try this in xaml:
<Window...>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Duration="00:00:1">
<DoubleAnimation Storyboard.TargetName="button1" From="6" To="25" Storyboard.TargetProperty="FontSize"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>
2) What are the properties I have to Animate in Button?
Target of Animation does not have to be a DependencyProperty
if that's what you're thinking. All properties can be the animation target. Although standard Animation classes does not support some types.
for example Background. you can animate Background.Color
using ColorAnimation
but not Background
itself because there's no BrushAnimation
. however you can implement custom animation for such properties.
Upvotes: 6