文字跳动动画"/>
WPF 文字跳动动画
演示:一串文字中单个文字顺序连续跳动
代码:
<Window x:Class="Test.Window1"xmlns=""xmlns:x=""xmlns:d=""xmlns:mc=""xmlns:local="clr-namespace:Test"xmlns:MyNamespace="clr-namespace:Test"mc:Ignorable="d" Name="win"xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"Title="Window1" Height="450" Width="800" Loaded="Window_Loaded"><Window.Resources><DrawingBrush x:Key="MyWireBrushResource" Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile"><DrawingBrush.Drawing><DrawingGroup><DrawingGroup.Children><GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="#66CCCCFF" /><GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="#66CCCCFF" /></DrawingGroup.Children></DrawingGroup></DrawingBrush.Drawing></DrawingBrush></Window.Resources><StackPanel VerticalAlignment="Center" HorizontalAlignment="Center"><Border x:Name="txtBd" Background="{StaticResource MyWireBrushResource}"><TextBlock x:Name="txt" Text="12345678" FontSize="60" Margin="40"><TextBlock.TextEffects><TextEffect PositionCount="1" x:Name="MyTextEffect"><TextEffect.Transform><TransformGroup><TranslateTransform x:Name="TextEffectTranslateTransform"/></TransformGroup></TextEffect.Transform></TextEffect></TextBlock.TextEffects><TextBlock.Triggers><EventTrigger RoutedEvent="TextBlock.Loaded"><BeginStoryboard><Storyboard><!-- Animates the Y factor of the TextEffect's TranslateTransform. --><DoubleAnimationStoryboard.TargetName="TextEffectTranslateTransform"Storyboard.TargetProperty="Y" From="0"To="20"Duration="00:00:0.25"RepeatBehavior="Forever"AutoReverse="True" /><!-- Animates the position of the TextEffect. --><Int32AnimationUsingKeyFramesStoryboard.TargetName="MyTextEffect"Storyboard.TargetProperty="PositionStart"Duration="0:0:4"AutoReverse="True"RepeatBehavior="Forever"><Int32AnimationUsingKeyFrames.KeyFrames><DiscreteInt32KeyFrame Value="0" KeyTime="0:0:0" /><DiscreteInt32KeyFrame Value="1" KeyTime="0:0:0.5" /><DiscreteInt32KeyFrame Value="2" KeyTime="0:0:1" /><DiscreteInt32KeyFrame Value="3" KeyTime="0:0:1.5" /><DiscreteInt32KeyFrame Value="4" KeyTime="0:0:2" /><DiscreteInt32KeyFrame Value="5" KeyTime="0:0:2.5" /><DiscreteInt32KeyFrame Value="6" KeyTime="0:0:3" /><DiscreteInt32KeyFrame Value="7" KeyTime="0:0:3.5" /><DiscreteInt32KeyFrame Value="8" KeyTime="0:0:4" /></Int32AnimationUsingKeyFrames.KeyFrames></Int32AnimationUsingKeyFrames></Storyboard></BeginStoryboard></EventTrigger></TextBlock.Triggers></TextBlock></Border><Rectangle Width="{Binding ActualWidth,ElementName=txtBd}" Height="{Binding ActualHeight,ElementName=txtBd}" HorizontalAlignment="Left" ><Rectangle.Fill><VisualBrush Visual="{Binding ElementName=txtBd}"><VisualBrush.RelativeTransform><TransformGroup><ScaleTransform ScaleX="1" ScaleY="-1"/><TranslateTransform Y="1"/></TransformGroup></VisualBrush.RelativeTransform></VisualBrush></Rectangle.Fill></Rectangle></StackPanel>
</Window>
更多推荐
WPF 文字跳动动画
发布评论