我的应用程序中有一个文本块,我想用它制作一个简单的动画。我只想它移动到左边,直到显然“离开设备”,然后返回到另一边,回到它的位置......好像水平地盘旋设备......永远重复这个!
我试过这样做:
<TextBlock x:Name="txbAnimated" FontFamily="Segoe WP SemiBold"
FontSize="17" Foreground="White" HorizontalAlignment="Center" Margin="0"
TextWrapping="Wrap" Text="My Text" VerticalAlignment="Center"
TextAlignment="Center">
<TextBlock.RenderTransform>
<CompositeTransform TranslateX="-550" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock x:Name="txbAnimated2" Margin="550,0,-550,0" FontFamily="Segoe WP
SemiBold" FontSize="17" Foreground="White" HorizontalAlignment="Center"
TextWrapping="Wrap" Text="My Text" VerticalAlignment="Center"
TextAlignment="Center">
<TextBlock.RenderTransform>
<CompositeTransform TranslateX="-550" />
</TextBlock.RenderTransform>
</TextBlock>
<Grid>
<StackPanel>
<StackPanel.Resources>
<Storyboard x:Name="movement">
<DoubleAnimation
Storyboard.TargetName="txbAnimated"
Duration="0:0:2"
Storyboard.TargetProperty=" (UIElement.RenderTransform).(CompositeTransform.TranslateX)"
From="0" To="-550"
BeginTime="0:0:10"
RepeatBehavior="1x"/>
</Storyboard>
<Storyboard x:Name="movement2">
<DoubleAnimation
Storyboard.TargetName="txbAnimated2"
Duration="0:0:2"
Storyboard.TargetProperty=" (UIElement.RenderTransform).(CompositeTransform.TranslateX)"
From="0" To="-550"
BeginTime="0:0:10"
RepeatBehavior="1x"/>
</Storyboard>
</StackPanel.Resources>
</StackPanel>
</Grid>
在Main:
private void StartBanner()
{
movement.Begin();
movement.Completed += movement_Completed;
movement2.Begin();
movement2.Completed += movement2_Completed;
}
private void movement_Completed(object sender, EventArgs e)
{
movement.Begin();
movement.Completed += movement2_Completed;
}
private void movement2_Completed(object sender, EventArgs e)
{
movement2.Begin();
movement2.Completed += movement_Completed;
}
我没有使用“RepeatBehavior = forever”因为我希望动画在一个周期后停止,等待几秒钟,然后重复它。
它以这种方式工作,但它干扰了UI上的其他元素行为...... 所以,我读了这篇文章Make animations smooth (XAML),但我正在使用Windows Phone 8,并不是所有适用于WP8的技巧......
有没有人知道制作这个动画的最佳方式,而不会弄乱UI上的其他元素?