Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Storyboard target setting wrong?!
4 replies. Latest Post by fyok2002 on December 6, 2008.
(0)
fyok2002
Member
2 points
5 Posts
12-04-2008 1:20 PM |
HI, I don't know if it is a but or not, bug it is strange. I have made an storyboard in XAML(SBsource), like change target's opacity from 1 to 0. and in C# codebehind, I could open image files from my computers(image[ i ]). and I also create storyboard for each image's(SBimage[ i ]). and I just make the storyboard I create in C# to equal to the one I create in XAML then change the target for each SBimage(SBimange[ i ] = SBsource; storyboard.SetTarget(SBimage[ i ],Image[ i ])). but when I running them, the only one will do the animation is the first image. the code as below:
Storyboard create in XAML:<Storyboard x:Name="SBsource"> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="" Storyboard.TargetProperty="(UIElement.Opacity)" BeginTime="00:00:00"> <SplineDoubleKeyFrame x:Name="staValue" KeyTime="00:00:00" Value="1"/> <SplineDoubleKeyFrame x:Name="endValue" KeyTime="00:00:00.5000000" Value="0"/> </DoubleAnimationUsingKeyFrames></Storyboard>
C# CodeBehind:Storyboard[] SBimage;SBimage = new Storyboard[image.Length]for (int i = 0; i < of.Files.Count(); i++) { image[ i ] = new Image(); source= new System.Windows.Media.Imaging.BitmapImage(); source.SetSource(of.Files.ElementAt(i).OpenRead()) ;//System.Windows.Controls.FileDialogFileInfo[])(of.Files))[ i ].OpenRead()); image[ i ].Source = source; GridImgField.Children.Add(image[ i ]); Storyboard.SetTarget(SBimage[ i ], image[ i ]); }
private void fade1_Click(object sender, RoutedEventArgs e) { SBimage[0].Begin(); }private void fade2_Click(object sender, RoutedEventArgs e){ SBimage[1].Begin();}
Here I just add to button to make image[0], and image[1] to do the animation, This is just brif code, but I just show you the idea, but the result is, what ever I click which button, the only image will changed the opacity is the image[1].
bryant
Star
9937 points
1,629 Posts
12-04-2008 2:08 PM |
When you call SBimange[ i ] = SBsource; you're not creating a new storyboard, just pointing to the storyboard that already exists. You need to create a new storyboard for each image for this to work.
12-05-2008 3:26 AM |
What you mean about create new storyboard? is just call SBimage[ i ]= new storyboard()? I have tried, it doing same thing. actually I have tried another way it is did same thing. I have create 2 new storyboard:
storyboard SB1 = new storyboard();storyboard SB2 = new storyboard();SB1 = SBsource;SB2 = SBsource;Storyboard.setTarget(SB1, image1);Storyboard.setTarget(SB2, image2);
and I create 2 button to make them begin. it still doing same thing.
12-05-2008 1:20 PM |
fyok2002:SB1 = SBsource;SB2 = SBsource;
You're still doing the same thing. SB1 and SB2 now both point to the same storyboard. You have to create a new storyboard and set the properties on that storyboard, not set it to a different storyboard.
12-06-2008 7:33 AM |
a ha, now I get it. thank you.