Page view counter
have some need it to get running Subscribe to this thread
Last post 12-13-2008 8:13 PM by hihoboy. 5 replies.
Sort Posts:
12-10-2008 12:50 AM
have some need it to get running
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(); }

Ahmad.Saad

Junior SW Developer

hihoboy

Loading...
Joined on 06-16-2008
Posts 49
12-10-2008 1:15 AM
Re: have some need it to get running

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.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

bryant

Loading...
Joined on 10-23-2002
Simi Valley, CA
Posts 1,153
12-10-2008 1:47 AM
Re: have some need it to get running
sorry I did what U told me but it still doesnt work I just see the red red triangle but it didnt move

Ahmad.Saad

Junior SW Developer

hihoboy

Loading...
Joined on 06-16-2008
Posts 49
12-10-2008 1:51 AM
Marked as Answer
Re: have some need it to get running

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();
    } 
}
 It works just fine when I run it. Are you getting any errors when you run your version?

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

bryant

Loading...
Joined on 10-23-2002
Simi Valley, CA
Posts 1,153
12-10-2008 12:40 PM
Re: Re: have some need it to get running

thx I am really glade of ur help   thx dude

Ahmad.Saad

Junior SW Developer

hihoboy

Loading...
Joined on 06-16-2008
Posts 49
12-13-2008 8:13 PM
Re: Re: have some need it to get running
hello if u can help I will be approtiated can u tell me how to covert this animation from transformation to scaling ?

Ahmad.Saad

Junior SW Developer

hihoboy

Loading...
Joined on 06-16-2008
Posts 49
Microsoft Communities