Re: Creating a storyboard from c# not working ...
Hi,
My name is Ibrahim working as SE in Hyd,India. Well I am new to Silverlight
I have created a line dynamically on canvas with position (x1,x2,y1,y2)=(80,230,50,50). and added to the canvas successfully at runtime.
i have written the code for animating a Line which was created dynamically. I want to deacrease/increase width From 10 To 100. For this Scenario I have written the Code
as shown below.
private void DrawLine(double x1,double x2,double y1,double y2)
{
Line horline1 = new Line();
horline1.Width = 150;
horline1.Height = 1;
horline1.X1 = x1;
horline1.X2 = x2;
horline1.Y1 = y1;
horline1.Y2 = y2;
SolidColorBrush stroke = new SolidColorBrush();
stroke.Color = Colors.White;
horline1.Stroke = stroke;
horline1.StrokeThickness = 1;
//surface is my convas name
surface.Children.Add(horline1);
Duration duration = new Duration(TimeSpan.FromSeconds(10));
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 10;
doubleAnimation.To = 100;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.AutoReverse = true;
doubleAnimation.Duration = duration;
Line line = new Line();
Storyboard.SetTarget(doubleAnimation, horline1);//if i created this line as Storyboard.SetTarget(doubleAnimation, new Line()); then line appears
//but not animating...
//Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(horline1.Width)"));
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));
Storyboard storyboard = new Storyboard();
storyboard.Duration = duration;
storyboard.RepeatBehavior = RepeatBehavior.Forever;
storyboard.AutoReverse = true;
storyboard.Children.Add(doubleAnimation);
storyboard.Begin();
}
After i call this method in my surface_loaded(canvas loaded) what i see is the line is not appearing.
any help will be appretiated...
Thanks in Advance
Ibrahim.