Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有WPF打字机的效果吗?_Wpf_Animation_Effect - Fatal编程技术网

有WPF打字机的效果吗?

有WPF打字机的效果吗?,wpf,animation,effect,Wpf,Animation,Effect,WPF中是否有与Flash的打字机效果相当的效果?打字机效果您指的是逐字显示的字符串 使用对象可以实现类似的效果,但是,必须手动输入每个字符串值 要自动创建此效果,您必须编写自己的动画对象,很可能是基于类的对象。打字机效果是指逐字显示的字符串 使用对象可以实现类似的效果,但是,必须手动输入每个字符串值 若要自动创建此效果,您必须编写自己的动画对象,最有可能是基于类的对象。好的,我成功了 private void TypewriteTextblock(string textToAnimate, T

WPF中是否有与Flash的打字机效果相当的效果?

打字机效果您指的是逐字显示的字符串

使用对象可以实现类似的效果,但是,必须手动输入每个字符串值


要自动创建此效果,您必须编写自己的动画对象,很可能是基于类的对象。

打字机效果是指逐字显示的字符串

使用对象可以实现类似的效果,但是,必须手动输入每个字符串值

若要自动创建此效果,您必须编写自己的动画对象,最有可能是基于类的对象。

好的,我成功了

private void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
    {
        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);
    }
但是有没有办法让角色淡入呢?

好的,我成功了

private void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
    {
        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);
    }

但是有没有办法让角色淡入呢?

谢谢你的提示!有了这些,我就可以做我贴出的答案了。淡入:我想这在字符串中很可能是不可能的,你必须采取全新的方法。制作一个WrapPanel并每隔N毫秒添加一个带有字母的TextBlock(您可以使用Dispatchermer)。然后可以使用DoubleAnimation类简单地使每个字母在一段时间内淡入(设置不透明属性的动画)。但是,这对较长的字符串不是很有效!谢谢你的提示!有了这些,我就可以做我贴出的答案了。淡入:我想这在字符串中很可能是不可能的,你必须采取全新的方法。制作一个WrapPanel并每隔N毫秒添加一个带有字母的TextBlock(您可以使用Dispatchermer)。然后可以使用DoubleAnimation类简单地使每个字母在一段时间内淡入(设置不透明属性的动画)。但是,这对较长的字符串不是很有效!对于后续问题,最好开始一个新的单独问题。如果你把它作为一个问题单独发布,更多的人会看到它并尝试回答。对于后续问题,最好从一个新的单独问题开始。如果你将它作为一个问题单独发布,更多的人会看到它并尝试回答。