我正在尝试使用 Composition Api 和 Expression Builder 来应用指针动画。我找到了我需要的样本,但代码不完整,我无法弄清楚如何获取变量center和distanceToCenter的值。原始文档和示例在这里:
https://docs.microsoft.com/en-us/windows/uwp/composition/pointer-input-animations
示例代码(稍作修改):
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
using EF = Microsoft.Toolkit.Uwp.UI.Animations.Expressions.ExpressionFunctions;
_tiltVisual = ElementCompositionPreview.GetElementVisual(element);
_pointerPositionPropSet = ElementCompositionPreview.GetPointerPositionPropertySet(element);
// || DEFINE THE EXPRESSION FOR THE ROTATION ANGLE ||
var hoverPosition = _pointerPositionPropSet.GetSpecializedReference<PointerPositionPropertySetReferenceNode>().Position;
var angleExpressionNode = EF.Conditional(hoverPosition == new Vector3(0, 0, 0),
ExpressionValues.CurrentValue.CreateScalarCurrentValue(),
35 * ((EF.Clamp(EF.Distance(center, hoverPosition), 0, distanceToCenter) % distanceToCenter) / distanceToCenter));
_tiltVisual.StartAnimation("RotationAngleInDegrees", angleExpressionNode);
// || DEFINE THE EXPRESSION FOR THE ROTATION AXIS ||
var axisAngleExpressionNode = EF.Vector3(-(hoverPosition.Y - center.Y) * EF.Conditional(hoverPosition.Y == center.Y, 0, 1),
(hoverPosition.X - center.X) * EF.Conditional(hoverPosition.X == center.X, 0, 1),
0);
_tiltVisual.StartAnimation("RotationAxis", axisAngleExpressionNode);