I use some WPF animation to move UserControl within vertically.
Here is the code
public void RestartAnimation(double contentControlHeight, double thisHeight)
{
if (cp != null && IsLoaded)
da.From = contentControlHeight;
da.To = -thisHeight;
da.RepeatBehavior = RepeatBehavior.Forever;
da.Duration = new Duration(TimeSpan.FromSeconds(this.Duration));
sb.Children.Clear();
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Top)"));
Storyboard.SetTarget(da, cp);
sb.Begin();
}
}
It works fine but I have discovered if the height is greater then the motion is faster.
So I need to realize 2 things:
Some speed range values ie 1-100 (very slow – super fast) and internally I need some formula/coefficient to do it.
I did some experiments with the static speed and different height and got some table.

Please help me to figure out which calculation I have to do to just set the speed range (1-100) and it should work fine regardless StackPanel height.
Thank you guys!
I’m not sure you should be interested in the ratio (StackPanel Height / ContentControl Height), but rather simply the difference (StackPanel Height – ContentControl Height).
Say that you want your speed to be 30 pixels per second (actually rather slow, but just going from your “speed” value above). You would be interested in setting your duration based on how many seconds it will take to cover the pixel distance (the difference in heights) at a rate of 30 pixels per second.
So you would just need:
This is how you would leave speed at a constant.