zoukankan      html  css  js  c++  java
  • WPF 跳动的文字

    先上代码

      public MainWindow()
            {
                InitializeComponent();
                //跳动的文字
               Storyboard perChar = new Storyboard();
                _text.TextEffects = new TextEffectCollection();
                for (int i = 0; i < _text.Text.Length; i++)
                {
                    TextEffect effect = new TextEffect();
                    effect.Transform = new TranslateTransform();
                    effect.PositionStart = i;
                    effect.PositionCount = 1;
                    _text.TextEffects.Add(effect);
    
                    DoubleAnimation anim = new DoubleAnimation();
                    anim.To = 25;
                    anim.AccelerationRatio = .2;
                    anim.DecelerationRatio = .2;
                    anim.RepeatBehavior = RepeatBehavior.Forever;
                    anim.AutoReverse = true;
                    anim.Duration = TimeSpan.FromSeconds(2);
                    anim.BeginTime = TimeSpan.FromMilliseconds(250 * i);
                    Storyboard.SetTargetProperty(anim, new PropertyPath("TextEffects[" + i + "].Transform.Y"));
                    Storyboard.SetTargetName(anim, _text.Name);
    
                    perChar.Children.Add(anim);
                }
                perChar.Begin(this);
         
            }

    效果图如下:

    前台代码如下:

      <TextBlock FontSize="36pt" Name="_text" Grid.Row="1" Grid.ColumnSpan="3" VerticalAlignment="Center" >
                This is animated Text
            </TextBlock>

     我是初学者,如有什么错误多多指教。也是为了留个印记说不定以后用的着。

    Top
    收藏
    关注
    评论
  • 相关阅读:
    Direct2D 变换
    DWrite 文字
    Windows基础窗体编程
    .net delegate(委托类型)
    详说new和overrid区别
    类与结构区别
    IIS的Gzip压缩
    ASP.NET 状态服务和session丢失问题解决方案
    Fiddler使用
    Castle系列教程(转)
  • 原文地址:https://www.cnblogs.com/smiler/p/3062724.html
Copyright © 2011-2022 走看看