以下のコードの目的は、マウスの水平方向の動きに親指を追従させることです。コードはマウス イベントで呼び出されるため、アニメーションのターゲット値は継続的に更新されます。
コードでoffset
は、現在のマウスの水平位置です。問題は、親指のアニメーションが指定された に完全にアニメーション化されずoffset
、常に小さい値または大きい値で停止しているように見えることです (マウスが左右にドラッグされているかどうかによって異なります)。
ドキュメントを読んでも、このSeekAlignedToLastTick()
関数が何をするのかわかりませんでしたが、アニメーションの動作に影響を与えます。
ドラッグ イベントにスムーズに追従するように、親指をアニメーション化するにはどうすればよいですか?
private Storyboard _thumbStoryboard;
private DoubleAnimation _thumbAnimation = new DoubleAnimation();;
private CompositeTransform _thumbTransform = new CompositeTransform();
private void UpdateUserInterface(double offset)
{
var thumbItem = Thumb as FrameworkElement;
if (_thumbStoryboard == null)
{
Storyboard.SetTarget(_thumbAnimation, _thumbTransform);
_thumbStoryboard = new Storyboard();
_thumbStoryboard.Children.Add(_thumbAnimation);
thumbItem.RenderTransform = _thumbTransform;
_thumbStoryboard.Duration = new Duration(TimeSpan.FromMilliseconds(100));
_thumbAnimation.EasingFunction = new ExponentialEase();
}
double from = _thumbTransform.TranslateX;
_thumbStoryboard.Stop();
Storyboard.SetTargetProperty(_thumbAnimation, new PropertyPath("TranslateX"));
_thumbAnimation.From = from;
_thumbAnimation.To = offset;
_thumbStoryboard.Begin();
_thumbStoryboard.SeekAlignedToLastTick(TimeSpan.Zero);
}