Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] [SilverLight / Wp7] Animate FontSize

Started by ferr May 8, 2010 at 7:01 PM 0 replies 1.8k views
Original Post
ferr
ferr
In the Win Phone 7 version of Silverlight, I am trying to animate the FontSize property of a TextBlock. I am getting an unhelpful error that I usually get when I specify a property that a dependency doesn't contain. Code looks like this,
                //animate text size
                DoubleAnimation da = new DoubleAnimation();
                da.Duration = new Duration(TimeSpan.FromSeconds(4.0));
                da.From = 10;
                da.To = 30;

                Storyboard sbText = new Storyboard();
                sbText.Duration = TimeSpan.FromSeconds(4.0);
                Storyboard.SetTarget(da, gameResult);
                Storyboard.SetTargetProperty(da, new PropertyPath(FontSizeProperty));
                sbText.Children.Add(da);
                sbText.Begin(); //Unhelpful error on this call

                gameResult.Text = "Player Busted!";

Are there a lot of issues with property animations like this? Another thing I was trying to do was animate a Margin property of an Image, but there is no MarginProperty (and the MSDN docs note that it's missing). [Edited by - ferr on May 8, 2010 7:36:28 PM]
jhunt1
jhunt1
The company I work for creates Kiosk applications, and we use WPF. This is basically how we do the bulk of our animations for our transitions, but you need to make a few adjustments:

DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(4.0));
da.From = 10;
da.To = 30;

Storyboard sbText = new Storyboard();

// you don't need to set storyboard's duration. it will be set to double animation's

// use SetTargetName, and pass in the TextBlock object's name
Storyboard.SetTargetName(da, gameResult.Name);
// Make sure you are using TextBlock.FontSizeProperty
Storyboard.SetTargetProperty(da, new PropertyPath(TextBlock.FontSizeProperty));
sbText.Children.Add(da);
sbText.Begin(this);
gameResult.Text = "Player Busted!";


And to answer your last question, there is a MarginProperty for Image. When you are setting the TargetProperty, be sure you are using new PropertyPath(TextBlock.FontSizeProperty) or new PropertyPath(Image.MarginProperty)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.