I have an animation inside a Behavior, but it is not running fluid.
Here is my animation code:
DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
animation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(0).(1)", UIElement.RenderTransformProperty, RotateTransform.AngleProperty));
int keyFrameCount = 16;
double timeOffsetInSeconds = 0.1;
int targetValue = 12;
double totalAnimationLength = keyFrameCount * timeOffsetInSeconds;
double repeatInterval = RepeatInterval;
bool isShaking = IsShaking;
// Can't be less than zero and pointless to be less than total length
if (repeatInterval < totalAnimationLength)
repeatInterval = totalAnimationLength;
animation.Duration = new Duration(TimeSpan.FromSeconds(repeatInterval));
for (int i = 0; i < keyFrameCount; i++)
{
animation.KeyFrames.Add(new LinearDoubleKeyFrame(i % 2 == 0 ? targetValue : -targetValue, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds))));
}
animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(totalAnimationLength))));
But, if i choose
int keyFrameCount = 360;
and
for (int i = 0; i < keyFrameCount; i++)
{
animation.KeyFrames.Add(new LinearDoubleKeyFrame(i, keyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds))));
}
it will rotate a very smooth circle.
How can I achieve to let the animation go from 0 to 30 degrees, back to -30 degrees,
and then back to 0 (to let it dither around a bit) AND have it look fluent.
After some tries, I see that (normal) back and forth will not work here,
it behaves totally uncontrolled!
I’m not really sure why you’re doing so many keyframes yourself, but in order to do
You could change the animation to something like