Как установить смещение для SpringVector3NaturalMotionAnimation? - PullRequest
0 голосов
/ 06 января 2019

Как установить точку offset для SpringVector3NaturalMotionAnimation? Используя следующий код, анимация работает хорошо, за исключением того, что я не могу установить точку смещения на середину FrameworkElement. Теперь offset находится в левом верхнем углу.

       private static void ScaleAnimation_Internal(FrameworkElement TargetFrameworkElement, int ScaleInProsents, TimeSpan Duration, TimeSpan Delay, int DampingRatioProsent)
        {
            AnimationClass TargetAnimationClass = AddScaleAnimation(TargetFrameworkElement);
            Compositor TargetCompositor = Window.Current.Compositor;
            //UPDATE
            TargetAnimationClass.TargetSpringVector3NaturalMotionAnimation.FinalValue = new Vector3((float)ScaleInProsents / 100);
            if (Duration != TimeSpan.Zero) TargetAnimationClass.TargetSpringVector3NaturalMotionAnimation.Period = Duration;
            if (Delay != TimeSpan.Zero) TargetAnimationClass.TargetSpringVector3NaturalMotionAnimation.DelayTime = Delay;
            if (DampingRatioProsent >= 0) TargetAnimationClass.TargetSpringVector3NaturalMotionAnimation.DampingRatio = (float)DampingRatioProsent / 100;
            //START ANIMATION
            TargetFrameworkElement.StartAnimation(TargetAnimationClass.TargetSpringVector3NaturalMotionAnimation);
        }

1 Ответ

0 голосов
/ 08 января 2019

Как сказал @Johnny Westlake, вам просто нужно установить CenterPoint до вызова StartAnimation. Например

Compositor _compositor = Window.Current.Compositor;
SpringVector3NaturalMotionAnimation _springAnimation;

private void Btn_PointerEntered(object sender, PointerRoutedEventArgs e)
{
    CreateOrUpdateSpringAnimation(1.5f);
    (sender as UIElement).CenterPoint = new Vector3((float)(Btn.ActualWidth / 2.0), (float)(Btn.ActualHeight / 2.0), 1f);
    (sender as UIElement).StartAnimation(_springAnimation);

}

private void Btn_PointerExited(object sender, PointerRoutedEventArgs e)
{
    CreateOrUpdateSpringAnimation(1.0f);
    (sender as UIElement).CenterPoint = new Vector3((float)(Btn.ActualWidth / 2.0), (float)(Btn.ActualHeight / 2.0), 1f);
    (sender as UIElement).StartAnimation(_springAnimation);


}
private void CreateOrUpdateSpringAnimation(float finalValue)
{
    if (_springAnimation == null)
    {
        _springAnimation = _compositor.CreateSpringVector3Animation();
        _springAnimation.Target = "Scale";

    }

    _springAnimation.FinalValue = new Vector3(finalValue);
}

Код Xaml

<Grid>
    <Button Name="Btn" Content="ClickMe" 
            PointerEntered="Btn_PointerEntered"
            PointerExited="Btn_PointerExited"
           VerticalAlignment="Center" HorizontalAlignment="Center" >

    </Button>
</Grid>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...