如何为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);
}
答案 0 :(得分:1)
正如@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>