Win universal app 视觉子通道上的合成动画

Win universal app 视觉子通道上的合成动画,win-universal-app,uwp,windows-10-universal,Win Universal App,Uwp,Windows 10 Universal,我使用UWP(Windows101607)中的新控件设置自定义控件的动画。我希望对其子对象的垂直偏移进行动画更改,但不希望对水平偏移进行更改 我可以像这样设置整个偏移(X和Y)的动画: var offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); offsetAnimation.Target = "Offset"; offsetAnimation.Duration = TimeSpan.FromSeconds(0.5);

我使用UWP(Windows101607)中的新控件设置自定义控件的动画。我希望对其子对象的垂直偏移进行动画更改,但不希望对水平偏移进行更改

我可以像这样设置整个偏移(X和Y)的动画:

var offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
offsetAnimation.Target = "Offset";
offsetAnimation.Duration = TimeSpan.FromSeconds(0.5);            
offsetAnimation.InsertExpressionKeyFrame(1.0f, "This.FinalValue");
animationCollection["Offset"] = offsetAnimation;
var visual = ElementCompositionPreview.GetElementVisual(child);
visual.ImplicitAnimations = animationCollection;
我希望这段代码只为子对象的Y偏移设置动画,但它根本不显示任何动画:

 var offsetAnimation = compositor.CreateScalarKeyFrameAnimation();
 offsetAnimation.Target = "Offset.Y";
 offsetAnimation.Duration = TimeSpan.FromSeconds(0.5);
 offsetAnimation.InsertExpressionKeyFrame(1.0f, "This.FinalValue");
 animationCollection["Offset"] = offsetAnimation;
 var visual = ElementCompositionPreview.GetElementVisual(child);
 visual.ImplicitAnimations = animationCollection;
将Target设置为“Offset.y”或将触发器设置为“Offset.y”没有帮助


我在文档中没有找到使用可视子通道的示例,因此,如果您能提供有关如何仅为偏移量的y通道设置动画的帮助,我将不胜感激。

根据您的代码片段,您可以为动画设置一个
偏移量
触发器。这意味着一旦更改了
子对象的偏移量
,该动画将开始。然后为
表达式关键帧
设置“This.FinalValue”,这样它会将您设置的值绑定到新偏移量,并将动画设置为新值

因此,如果我们只是将新偏移设置为仅更改
y
值(让
x
z
与旧偏移相同),动画将仅为
y
通道设置动画

代码如下:

<TextBlock x:Name="txtanimation" Text="animation test" Height="30" Width="100" Foreground="Red" ></TextBlock>
<Button x:Name="btnanimate" Click="btnanimate_Click" Content="Animate y" Margin="60"></Button>
结果是:


更多样品请参考。还有更多细节,您可以参考视频,如。

根据您的代码片段,您可以为动画设置一个
Offset
触发器。这意味着一旦更改了
子对象的偏移量
,该动画将开始。然后为
表达式关键帧
设置“This.FinalValue”,这样它会将您设置的值绑定到新偏移量,并将动画设置为新值

因此,如果我们只是将新偏移设置为仅更改
y
值(让
x
z
与旧偏移相同),动画将仅为
y
通道设置动画

代码如下:

<TextBlock x:Name="txtanimation" Text="animation test" Height="30" Width="100" Foreground="Red" ></TextBlock>
<Button x:Name="btnanimate" Click="btnanimate_Click" Content="Animate y" Margin="60"></Button>
结果是:

更多样品请参考。更多细节,你可以参考视频,如