WPF 文字跳动动画

编程入门 行业动态 更新时间:2024-10-25 15:26:47

WPF <a href=https://www.elefans.com/category/jswz/34/1769559.html style=文字跳动动画"/>

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 文字跳动动画

本文发布于:2024-03-09 07:57:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1724383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文字   动画   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!