要UWP動畫剪輯,我們可以使用ObjectAnimationUsingKeyFrames與Grid.Clip
類似以下內容:
<Storyboard x:Name="Storyboard1">
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="grid" Storyboard.TargetProperty="Grid.Clip">
<DiscreteObjectKeyFrame KeyTime="0:0:0.25">
<DiscreteObjectKeyFrame.Value>
<RectangleGeometry Rect="0,0,55,34" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.50">
<DiscreteObjectKeyFrame.Value>
<RectangleGeometry Rect="0,0,65,34" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.75">
<DiscreteObjectKeyFrame.Value>
<RectangleGeometry Rect="0,0,75,34" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:1">
<DiscreteObjectKeyFrame.Value>
<RectangleGeometry Rect="0,0,90,34" />
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
...
<Grid x:Name="grid"
Width="90"
Height="34"
Background="Red"
BorderBrush="Black"
BorderThickness="2"
RenderTransformOrigin="0.5,0.5">
<Grid.Clip>
<RectangleGeometry Rect="0,0,45,34" />
</Grid.Clip>
<TextBlock Margin="4" Foreground="White">Hello world</TextBlock>
</Grid>
然而,這是一個關鍵幀動畫,如果你需要的線性插值動畫,你可以嘗試如下:
<Storyboard x:Name="Storyboard1">
<DoubleAnimation Duration="0:0:1"
Storyboard.TargetName="grid"
Storyboard.TargetProperty="(UIElement.Clip).(Geometry.Transform).(CompositeTransform.TranslateX)"
To="0" />
</Storyboard>
...
<Grid x:Name="grid"
Width="90"
Height="34"
Background="Red"
BorderBrush="Black"
BorderThickness="2"
RenderTransformOrigin="0.5,0.5">
<Grid.Clip>
<RectangleGeometry Rect="0,0,90,34">
<RectangleGeometry.Transform>
<CompositeTransform TranslateX="-45" />
</RectangleGeometry.Transform>
</RectangleGeometry>
</Grid.Clip>
<TextBlock Margin="4" Foreground="White">Hello world</TextBlock>
</Grid>
謝謝,這真的解釋了一切。如果可能的話,我會給你一個Storyboard.TargetProperty中的語法的額外點:-) – PEK