首页 > 其他分享 >WPF 打字效果

WPF 打字效果

时间:2023-03-05 22:11:32浏览次数:30  
标签:story Storyboard stringAnimationUsingKeyFrames 效果 打字 爱祖国 discreteStringKeyFrame 

利用 StringAnimationUsingKeyFrames:

 

 public ChatGPTWindow()
        {
            InitializeComponent();
            txt1.Text = "";//Textblock control
            TypewriteTextblock("我爱北京天安门,我爱祖国,我爱北京天安门,我爱祖国,我爱北京天安门,我爱祖国,我爱北京天安门,我爱祖国,我爱祖国我爱祖国我爱祖国", txt1);

        }
        private void TypewriteTextblock(string textToAnimate, TextBlock txt)
        {

            TimeSpan timeSpan = TimeSpan.FromSeconds(textToAnimate.Length/2);//相当于速度
            Storyboard story = new Storyboard();
            story.FillBehavior = FillBehavior.HoldEnd;
            story.RepeatBehavior = RepeatBehavior.Forever;

            DiscreteStringKeyFrame discreteStringKeyFrame;
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();
            stringAnimationUsingKeyFrames.Duration = new Duration(timeSpan);

            string tmp = string.Empty;
            foreach (char c in textToAnimate)
            {
                discreteStringKeyFrame = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.Paced;
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);

            story.Begin(txt);
        }

  

标签:story,Storyboard,stringAnimationUsingKeyFrames,效果,打字,爱祖国,discreteStringKeyFrame,
From: https://www.cnblogs.com/wgscd/p/17181883.html

相关文章

  • HTML与CSS手写-1.手写图片瀑布流效果
    1.column多行布局实现瀑布流column 实现瀑布流主要依赖两个属性。column-count 属性,是控制屏幕分为多少列。column-gap 属性,是控制列与列之间的距离。<!DOCTYPEht......
  • flex控件拖拽效果
    <?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"backgroundColor="#D99191"><mx:Arrayid="coffee......
  • WPF 界面布局、常用控件入门教程实例 WPF入门学习控件快速教程例子 WPF上位机、工控串
    WPF(WindowsPresentationFoundation)是一种用于创建Windows桌面应用程序的框架,它提供了丰富的控件库和灵活的界面布局,可以创建现代化的用户界面。下面是WPF入门学......
  • WPF MVVM动态绑定实现
    UI与后端绑定有两种方式1.在xaml的后台代码中进行设置,如下publicMainWindow(){InitializeComponent();this.DataContext......
  • 记录--手摸手带你撸一个拖拽效果
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助前言最近看见一个拖拽效果的视频(抖音:艾恩小灰灰),看好多人评论说跟着敲也没效果,还有就是作者也不回复大......
  • 无感知WPF窗口
    在窗口的XAML文件中添加以下属性:ShowInTaskbar="False"这将使窗口不显示在任务栏上,并且不会出现在Alt+Tab切换列表中。在窗口的代码中,覆盖OnSourceInitialized方......
  • vue实现app页面切换效果
    pageAninmatevue-router实现webApp切换效果快速集成1.复制PageTransittion.vue到项目目录。2.修改router配置。Router.prototype.goBack=function(){this.isB......
  • 使用 CSS 实现页面加载的淡入效果
    可以使用CSS过渡让文本段落在页面加载时淡入吗?我真的很喜欢它在http://dotmailapp.com/上的样子,并且很想使用CSS来使用类似的效果。该域名已被购买,不再具有提及的......
  • 我们软件与钉钉集成调用的实例测试效果
    我们的软件已经完成阿里钉钉的接口集成工作。下面是调用接口获取到的查询结果图示:......
  • 如何使用Blender制作卡通三渲二效果
    推荐:将 ​​NSDT场景编辑器​​ 加入你的3D开发工具链。  今天来分享一个在Blender中实现简单卡通三渲二效果和卡通描边的方法,基础的卡通三渲二效果在Blender中还是很简......