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
    收藏
    关注
    评论
  • 相关阅读:
    08.3 属性描述符__get__ __set__ __delete__
    08.2 __getattr__ 和 __getattribute__
    08.1 property 装饰器
    appium脚本编写,元素定位,隐式等待
    appium的安装和介绍
    docker镜像构建
    dockerfile的语法和指令
    docker的registry介绍
    docker-compose使用
    docker部署Jenkins
  • 原文地址:https://www.cnblogs.com/smiler/p/3062724.html
Copyright © 2011-2022 走看看