Skip to main content
Home Forums Silverlight Programming Visual Studio & Silverlight Development Tools have some need it to get running
5 replies. Latest Post by hihoboy on December 13, 2008.
(0)
hihoboy
Member
24 points
49 Posts
12-10-2008 12:50 AM |
Hello every body its my first day to join this community I have some code of procedural animation I want to know how to get it running I have tried several methods but I couldn't so if anybody can help me I will be glad here is the function .. private void Create_And_Run_Animation(object sender, EventArgs e) { // Create a red rectangle that will be the target // of the animation. Rectangle myRectangle = new Rectangle(); myRectangle.Width = 200; myRectangle.Height = 200; Color myColor = Color.FromArgb(255, 255, 0, 0); SolidColorBrush myBrush = new SolidColorBrush(); myBrush.Color = myColor; myRectangle.Fill = myBrush; // Add the rectangle to the tree. LayoutRoot.Children.Add(myRectangle); // Create a duration of 2 seconds. Duration duration = new Duration(TimeSpan.FromSeconds(2)); // Create two DoubleAnimations and set their properties. DoubleAnimation myDoubleAnimation1 = new DoubleAnimation(); DoubleAnimation myDoubleAnimation2 = new DoubleAnimation(); myDoubleAnimation1.Duration = duration; myDoubleAnimation2.Duration = duration; Storyboard sb = new Storyboard(); sb.Duration = duration; sb.Children.Add(myDoubleAnimation1); sb.Children.Add(myDoubleAnimation2); Storyboard.SetTarget(myDoubleAnimation1, myRectangle); Storyboard.SetTarget(myDoubleAnimation2, myRectangle); // Set the attached properties of Canvas.Left and Canvas.Top // to be the target properties of the two respective DoubleAnimations. Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(Canvas.Top)")); myDoubleAnimation1.To = 200; myDoubleAnimation2.To = 200; // Make the Storyboard a resource. LayoutRoot.Resources.Add("unique_id", sb); // Begin the animation. sb.Begin(); }
bryant
Star
9937 points
1,629 Posts
12-10-2008 1:15 AM |
hihoboy:// Make the Storyboard a resource. LayoutRoot.Resources.Add("unique_id", sb);
Comment out that line and it should work. I hooked it to a UserControl Loaded event with a Canvas at the root and it worked fine.
12-10-2008 1:47 AM |
sorry I did what U told me but it still doesnt work I just see the red red triangle but it didnt move
12-10-2008 1:51 AM |
You should see a Red Rectangle. Anyhow, here is my code:
<UserControl x:Class="SilverlightTesting.TestAni" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Canvas x:Name="LayoutRoot" Background="White"> </Canvas> </UserControl>
public partial class TestAni : UserControl { public TestAni() { InitializeComponent(); Loaded += new RoutedEventHandler(Create_And_Run_Animation); } private void Create_And_Run_Animation(object sender, RoutedEventArgs e) { // Create a red rectangle that will be the target // of the animation. Rectangle myRectangle = new Rectangle(); myRectangle.Width = 200; myRectangle.Height = 200; Color myColor = Color.FromArgb(255, 255, 0, 0); SolidColorBrush myBrush = new SolidColorBrush(); myBrush.Color = myColor; myRectangle.Fill = myBrush; // Add the rectangle to the tree. LayoutRoot.Children.Add(myRectangle); // Create a duration of 2 seconds. Duration duration = new Duration(TimeSpan.FromSeconds(2)); // Create two DoubleAnimations and set their properties. DoubleAnimation myDoubleAnimation1 = new DoubleAnimation(); DoubleAnimation myDoubleAnimation2 = new DoubleAnimation(); myDoubleAnimation1.Duration = duration; myDoubleAnimation2.Duration = duration; Storyboard sb = new Storyboard(); sb.Duration = duration; sb.Children.Add(myDoubleAnimation1); sb.Children.Add(myDoubleAnimation2); Storyboard.SetTarget(myDoubleAnimation1, myRectangle); Storyboard.SetTarget(myDoubleAnimation2, myRectangle); // Set the attached properties of Canvas.Left and Canvas.Top // to be the target properties of the two respective DoubleAnimations. Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(Canvas.Top)")); myDoubleAnimation1.To = 200; myDoubleAnimation2.To = 200; // Make the Storyboard a resource. //LayoutRoot.Resources.Add("unique_id", sb); // Begin the animation. sb.Begin(); } }
12-10-2008 12:40 PM |
thx I am really glade of ur help thx dude
12-13-2008 8:13 PM |
hello if u can help I will be approtiated can u tell me how to covert this animation from transformation to scaling ?