All,
Can someone tell me why this KeyTime is telling me it is a negative value at runtime? I’ve removed some logic that builds a path to an image.
public Storyboard CreateAnimationStoryBoard(DependencyObject dependencyObjectTarget,Image targetImage)
{
try
{
Storyboard sb = new Storyboard();
Storyboard.SetTarget(sb, dependencyObjectTarget);
Storyboard.SetTargetName(sb, targetImage.Name);
Storyboard.SetTargetProperty(sb, new PropertyPath(Image.SourceProperty));
ObjectAnimationUsingKeyFrames oaukf = new ObjectAnimationUsingKeyFrames();
oaukf.Duration = TimeSpan.FromSeconds(animationLength);
oaukf.BeginTime = new TimeSpan(0, 0, 0);
for (int i = startFrame; i <= endFrame; i++)
{
*build an animation string path here (hidden)*
Uri u;
Uri.TryCreate(animationString.ToString(), UriKind.RelativeOrAbsolute, out u);
BitmapImage bi = new BitmapImage(u);
DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame();
dokf.KeyTime = KeyTime.Uniform;
dokf.Value = bi;
oaukf.KeyFrames.Add(dokf);
}
sb.Children.Add(oaukf);
return sb;
}
Now, specifically, at runtime, it tells me that “KeyTime property on KeyFrame object must be set to a non-negative TimeSpan value”. If I dive a bit deeper in the variable, I get no further debugging information. I’ve checked if the bitmaps are null, which they aren’t. I’ve tried setting my own timespan (to 1 second) for example, and I get the same error as above.
This all stems from a similar function I have in WPF that builds a storyboard in this exact manner. The only difference in the two is that the Keytime is set to KeyTime.PACED in wpf. Since Silverlight apparently doesn’t have this option, I used Uniform and have run into this error. Can someone shed some light on why this is happening in Silverlight, but works completely fine in WPF?
Your use of the Keytime variable is a bit off:
In setting your keyframe, say on Visibility, use this: