///--Method private Storyboard SetSb() { TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(this.TargetText.Length / this.TypeSpeed * 1000)); DiscreteStringKeyFrame discreteStringKeyFrame; StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames(); stringAnimationUsingKeyFrames.Duration = new Duration(timeSpan); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); string tmp = string.Empty; foreach (char c in this.TargetText) { discreteStringKeyFrame = new DiscreteStringKeyFrame(); discreteStringKeyFrame.KeyTime = KeyTime.Paced; tmp += c; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } Storyboard sb = Application.Current.Resources["Sb_TypeWriter"] as Storyboard; sb.Children.Add(stringAnimationUsingKeyFrames); return(sb); }
/// <summary> /// 在指定的文字层绑定控件上进行打字动画 /// </summary> /// <param name="appendString">要追加的字符串</param> /// <param name="msglayBinding">文字层的控件</param> /// <param name="wordTimeSpan">字符之间的打字时间间隔</param> private void TypeWriter(string appendString, TextBlock msglayBinding, int wordTimeSpan) { MsgLayerTypingStory = new Storyboard(); StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames(); Duration aniDuration = new Duration(TimeSpan.FromMilliseconds(wordTimeSpan * appendString.Length + 2000)); stringAnimationUsingKeyFrames.Duration = aniDuration; MsgLayerTypingStory.Duration = aniDuration; string tmp = String.Empty; int ctr = 0; foreach (char c in appendString) { var discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ctr++ *wordTimeSpan)) }; tmp += c; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } Storyboard.SetTarget(stringAnimationUsingKeyFrames, msglayBinding); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); MsgLayerTypingStory.Children.Add(stringAnimationUsingKeyFrames); MsgLayerTypingStory.RepeatBehavior = RepeatBehavior.Forever; MsgLayerTypingStory.Begin(); }
private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan) { var story = new Storyboard { FillBehavior = FillBehavior.HoldEnd }; DiscreteStringKeyFrame discreteStringKeyFrame; var stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames { Duration = new Duration(timeSpan) }; var tmp = string.Empty; foreach (var c in textToAnimate) { discreteStringKeyFrame = new 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); //story.Stop(txt); }
private StringAnimationUsingKeyFrames MakeTypewriteTextblock(string textToAnimate, string typeTextBlockName) { StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames(); stringAnimationUsingKeyFrames.FillBehavior = FillBehavior.HoldEnd; DiscreteStringKeyFrame discreteStringKeyFrame; string tmp = string.Empty; for (int i = 0; i <= textToAnimate.Length; i++) { discreteStringKeyFrame = new DiscreteStringKeyFrame(); discreteStringKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300 * i)); //KeyTime.Paced; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); if (i == textToAnimate.Length) { break; } tmp += textToAnimate[i]; } Storyboard.SetTargetName(stringAnimationUsingKeyFrames, typeTextBlockName); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); return(stringAnimationUsingKeyFrames); }
private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan) { Storyboard storyboard = new Storyboard() { FillBehavior = FillBehavior.HoldEnd }; StringAnimationUsingKeyFrames stringAnimationUsingKeyFrame = new StringAnimationUsingKeyFrames() { Duration = new Duration(timeSpan) }; string empty = string.Empty; string str = textToAnimate; for (int i = 0; i < str.Length; i++) { char chr = str[i]; DiscreteStringKeyFrame discreteStringKeyFrame = new DiscreteStringKeyFrame() { KeyTime = KeyTime.Paced }; empty = string.Concat(empty, chr.ToString()); discreteStringKeyFrame.Value = empty; stringAnimationUsingKeyFrame.KeyFrames.Add(discreteStringKeyFrame); } Storyboard.SetTargetName(stringAnimationUsingKeyFrame, txt.Name); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrame, new PropertyPath(TextBlock.TextProperty)); storyboard.Children.Add(stringAnimationUsingKeyFrame); storyboard.Begin(txt); }
public static void TypeWriter(string textToAnimate, TextBlock txt, TimeSpan timeSpan) { Storyboard story = new Storyboard(); story.FillBehavior = FillBehavior.HoldEnd; StringAnimationUsingKeyFrames saukf = new StringAnimationUsingKeyFrames(); saukf.Duration = new Duration(timeSpan); string tmp = string.Empty; foreach (char c in textToAnimate) { DiscreteStringKeyFrame dskf = new DiscreteStringKeyFrame(); dskf.KeyTime = KeyTime.Paced; tmp += c; dskf.Value = tmp; saukf.KeyFrames.Add(dskf); } Storyboard.SetTargetName(saukf, txt.Name); Storyboard.SetTargetProperty(saukf, new PropertyPath(TextBlock.TextProperty)); story.Children.Add(saukf); story.Begin(txt); }
/// <summary> /// 在指定的文字层绑定控件上进行打字动画 /// </summary> /// <param name="orgString">原字符串</param> /// <param name="appendString">要追加的字符串</param> /// <param name="msglayBinding">文字层的控件</param> /// <param name="wordTimeSpan">字符之间的打字时间间隔</param> private void TypeWriter(string orgString, string appendString, TextBlock msglayBinding, int wordTimeSpan) { //this.HideMessageTria(); Storyboard MsgLayerTypingStory = new Storyboard(); StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames(); Duration aniDuration = new Duration(TimeSpan.FromMilliseconds(wordTimeSpan * appendString.Length)); stringAnimationUsingKeyFrames.Duration = aniDuration; MsgLayerTypingStory.Duration = aniDuration; string tmp = orgString; foreach (char c in appendString) { var discreteStringKeyFrame = new DiscreteStringKeyFrame(); discreteStringKeyFrame.KeyTime = KeyTime.Paced; tmp += c; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } Storyboard.SetTarget(stringAnimationUsingKeyFrames, msglayBinding); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); MsgLayerTypingStory.Children.Add(stringAnimationUsingKeyFrames); MsgLayerTypingStory.Completed += this.TypeWriterAnimationCompletedCallback; MsgLayerTypingStory.Begin(); MsgStoryboard = MsgLayerTypingStory; }
private void FillStoryBoard2(char c, TextBlock t) { ColorAnimation colani = new ColorAnimation() { BeginTime = TimeSpan.FromMilliseconds(400 * 19), From = Colors.LightBlue, To = Colors.Transparent, Duration = TimeSpan.FromMilliseconds(300) }; SolidColorBrush s = new SolidColorBrush(Colors.LightBlue); ColorAnimation colani2 = new ColorAnimation() { BeginTime = TimeSpan.FromMilliseconds(400 * 19), From = Colors.LightBlue, To = Colors.Transparent, Duration = TimeSpan.FromMilliseconds(300) }; SolidColorBrush s2 = new SolidColorBrush(Colors.LightBlue); StringAnimationUsingKeyFrames stas = new StringAnimationUsingKeyFrames(); DiscreteStringKeyFrame desc = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(_time)); DiscreteStringKeyFrame desc2 = new DiscreteStringKeyFrame(c + "", TimeSpan.FromMilliseconds(_time + 300)); stas.KeyFrames.Add(desc); stas.KeyFrames.Add(desc2); t.Background = s; if (_settings.Action == 0) { ((TextBlock)LeftPanel.Children[RightPanel.Children.Count - 1]).Background = s2; } else { ((TextBlock)RightPanel.Children[LeftPanel.Children.Count - 1]).Background = s2; } Storyboard.SetTarget(stas, t); Storyboard.SetTargetProperty(stas, new PropertyPath("(Text)")); if (_settings.Action == 0) { Storyboard.SetTarget(colani2, (TextBlock)LeftPanel.Children[RightPanel.Children.Count - 1]); Storyboard.SetTargetProperty(colani2, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)")); } else { Storyboard.SetTarget(colani2, (TextBlock)RightPanel.Children[LeftPanel.Children.Count - 1]); Storyboard.SetTargetProperty(colani2, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)")); } Storyboard.SetTarget(colani, t); Storyboard.SetTargetProperty(colani, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)")); _time += 400; St.Children.Add(stas); St.Children.Add(colani); St.Children.Add(colani2); }
public void addStringAnimation(String control, String value, Object property, int duration) { StringAnimationUsingKeyFrames anim = new StringAnimationUsingKeyFrames(); DiscreteStringKeyFrame edkf = new DiscreteStringKeyFrame(); edkf.Value = value; edkf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)); anim.KeyFrames.Add(edkf); anim.BeginTime = TimeSpan.FromSeconds(beginTime); beginTime += duration; if (duration > 0) { animTimer.Add(beginTime); } Storyboard.SetTargetName(anim, control); Storyboard.SetTargetProperty(anim, new PropertyPath(property)); sb.Children.Add(anim); }
private void StartCountdown(FrameworkElement target) { var countdownAnimation = new StringAnimationUsingKeyFrames(); for (var i = 5; i > 0; i--) { var keyTime = TimeSpan.FromSeconds(5 - i); var frame = new DiscreteStringKeyFrame(i.ToString(), KeyTime.FromTimeSpan(keyTime)); countdownAnimation.KeyFrames.Add(frame); } countdownAnimation.KeyFrames.Add(new DiscreteStringKeyFrame(" ", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6)))); Storyboard.SetTargetName(countdownAnimation, target.Name); Storyboard.SetTargetProperty(countdownAnimation, new PropertyPath(TextBlock.TextProperty)); countdownStoryboard = new Storyboard(); countdownStoryboard.Children.Add(countdownAnimation); countdownStoryboard.Completed += CountdownTimer_Completed; countdownStoryboard.Begin(this); }
private void FillStoryBoard(char c, TextBlock t, Boolean timer) { StringAnimationUsingKeyFrames stas = new StringAnimationUsingKeyFrames(); DiscreteStringKeyFrame desc = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(_time)); DiscreteStringKeyFrame desc2 = new DiscreteStringKeyFrame(c + "", TimeSpan.FromMilliseconds(_time + 300)); DiscreteStringKeyFrame desc3 = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(400 * 19)); stas.KeyFrames.Add(desc); stas.KeyFrames.Add(desc2); stas.KeyFrames.Add(desc3); Storyboard.SetTarget(stas, t); Storyboard.SetTargetProperty(stas, new PropertyPath("(Text)")); if (timer) { _time += 400; } St.Children.Add(stas); }
private void startCountDown(FrameworkElement target) { var remainingTime = 120; for (var i = remainingTime; i > 0; i--) { var keyTime = TimeSpan.FromSeconds(remainingTime - i); var frame = new DiscreteStringKeyFrame("Time: " + i.ToString() + "s", KeyTime.FromTimeSpan(keyTime)); countDownAnimation.KeyFrames.Add(frame); } countDownAnimation.KeyFrames.Add(new DiscreteStringKeyFrame("Time's up!", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(remainingTime + 1)))); Storyboard.SetTargetName(countDownAnimation, target.Name); Storyboard.SetTargetProperty(countDownAnimation, new PropertyPath(TextBlock.TextProperty)); countdownStoryboard.Children.Add(countDownAnimation); countdownStoryboard.Completed += CountdownTimerCompleted; countdownStoryboard.Begin(this); }
public void Typewriter(string text, TextBlock block, TimeSpan timespan) { story.FillBehavior = FillBehavior.HoldEnd; DiscreteStringKeyFrame discreteStringKeyFrame; StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames(); stringAnimationUsingKeyFrames.Duration = new Duration(timespan); string tmp = string.Empty; foreach (char c in text) { discreteStringKeyFrame = new DiscreteStringKeyFrame(); discreteStringKeyFrame.KeyTime = KeyTime.Paced; tmp += c; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } Storyboard.SetTargetName(stringAnimationUsingKeyFrames, block.Name); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); story.Children.Add(stringAnimationUsingKeyFrames); }
private void WorkingAnimation(TextBlock control) { if (_story != null) { _story.Stop(this); } _story = new Storyboard(); _story.FillBehavior = FillBehavior.HoldEnd; _story.RepeatBehavior = RepeatBehavior.Forever; StringAnimationUsingKeyFrames stringAnimation = new StringAnimationUsingKeyFrames(); stringAnimation.Duration = TimeSpan.FromSeconds(2); stringAnimation.FillBehavior = FillBehavior.Stop; stringAnimation.RepeatBehavior = RepeatBehavior.Forever; Storyboard.SetTargetName(stringAnimation, control.Name); Storyboard.SetTargetProperty(stringAnimation, new PropertyPath(TextBlock.TextProperty)); DiscreteStringKeyFrame kf1 = new DiscreteStringKeyFrame("Working", TimeSpan.FromSeconds(0)); DiscreteStringKeyFrame kf2 = new DiscreteStringKeyFrame(".Working.", TimeSpan.FromSeconds(0.5)); DiscreteStringKeyFrame kf3 = new DiscreteStringKeyFrame("..Working..", TimeSpan.FromSeconds(1)); DiscreteStringKeyFrame kf4 = new DiscreteStringKeyFrame("...Working...", TimeSpan.FromSeconds(1.5)); stringAnimation.KeyFrames.Add(kf1); stringAnimation.KeyFrames.Add(kf2); stringAnimation.KeyFrames.Add(kf3); stringAnimation.KeyFrames.Add(kf4); _story.Children.Add(stringAnimation); DoubleAnimation doubleAnimation = new DoubleAnimation(-2.5, 3.5, TimeSpan.FromSeconds(5.4)); Storyboard.SetTargetName(doubleAnimation, control.Name + "_gs2"); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(GradientStop.OffsetProperty)); doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; _story.Children.Add(doubleAnimation); _story.Begin(this, true); }
private void Typewriter(List <string> sAnim, TextBlock txt, TimeSpan span) { Storyboard story = new Storyboard { FillBehavior = FillBehavior.HoldEnd, RepeatBehavior = RepeatBehavior.Forever }; DiscreteStringKeyFrame discreteStringKeyFrame; StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames { Duration = new Duration(span) }; for (int i = 0; i < 15; i++) { discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Uniform, Value = string.Empty }; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } foreach (string s in sAnim) { string tmp = string.Empty; foreach (char c in s) { discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Uniform }; tmp += c; discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } for (int i = 0; i < 10; i++) { discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Uniform, Value = tmp }; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } for (int i = 0; i < s.Length; i++) { discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Uniform }; tmp = tmp.Remove(tmp.Length - 1, 1); discreteStringKeyFrame.Value = tmp; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Uniform, Value = string.Empty }; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); } Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name); Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); story.Children.Add(stringAnimationUsingKeyFrames); story.Begin(txt); }
public void ShowWaitAnimation() { try { LoadingAnimationBorder.Child = null; LoadingAnimationGrid.Visibility = Visibility.Visible; var stackPanel = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; LoadingAnimationBorder.Child = stackPanel; //var circularFadingLine = new CircularFadingLine(); var vw = new VisualWrapper { Child = CreateAnnimationOnWorkerThread(), Width = 17, Height = 17, Margin = new Thickness(0, 0, 5, 0) }; stackPanel.Children.Add(vw); var textBlock = new TextBlock { Width = 80 }; var stranim = new StringAnimationUsingKeyFrames { AutoReverse = false, RepeatBehavior = RepeatBehavior.Forever, Duration = new Duration(new TimeSpan(0, 0, 0, 2)) }; var kf1 = new DiscreteStringKeyFrame { Value = "Загрузка", KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0)) }; var kf2 = new DiscreteStringKeyFrame { Value = "Загрузка.", KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 500)) }; var kf3 = new DiscreteStringKeyFrame { Value = "Загрузка..", KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1)) }; var kf4 = new DiscreteStringKeyFrame { Value = "Загрузка...", KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1, 500)) }; stranim.KeyFrames.Add(kf1); stranim.KeyFrames.Add(kf2); stranim.KeyFrames.Add(kf3); stranim.KeyFrames.Add(kf4); stackPanel.Children.Add(textBlock); textBlock.BeginAnimation(TextBlock.TextProperty, stranim); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void Add(string text, int code) { base.Dispatcher.Invoke(() => { if (!string.IsNullOrEmpty(text)) { TextBlock textBlock = new TextBlock(); logPanel.Children.Add(textBlock); logCount++; textBlock.Name = "text" + logCount.ToString(); //if (!atAnimation) { atAnimation = true; double EndY; TextBlock prev = logPanel.Children[0] as TextBlock; if (prev.ActualHeight != double.NaN) { if (prev.ActualHeight < 20) { EndY = -(logCount * prev.ActualHeight / 1.0f - GlobalOutLogScrollViewer.ActualHeight) - 20.0f; } else { EndY = -(logCount * prev.ActualHeight / 4.0f - GlobalOutLogScrollViewer.ActualHeight); } } else { EndY = -logCount * 15; } DoubleAnimation AnimationY = new DoubleAnimation(saveY, EndY, TimeSpan.FromSeconds(1)); AnimationY.Completed += AnimationY_Completed; saveY = EndY; TranslateTransform Transform = new TranslateTransform(); logPanel.RenderTransform = Transform; Transform.BeginAnimation(TranslateTransform.YProperty, AnimationY); } ColorAnimation animation = new ColorAnimation { Duration = new Duration(TimeSpan.FromSeconds(10)) }; /* * switch (code) * { * case 0: * animation.To = SystemColors.ControlTextColor; * textBlock.Foreground = SystemColors.ControlTextBrush; * break; * case 1: * animation.To = SystemColors.WindowFrameColor; * textBlock.Foreground = SystemColors.ScrollBarBrush; * break; * case 3: * animation.To = ((SolidColorBrush)App.Current.Resources["OWLOSDangerAlpha4"]).Color; * textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSDanger"]).Color); * break; * default: * animation.To = SystemColors.HotTrackColor; * textBlock.Foreground = SystemColors.MenuBarBrush; * break; * } */ switch (code) { case 0: animation.To = SystemColors.ControlTextColor; textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSSecondary"]).Color); break; case 1: animation.To = ((SolidColorBrush)App.Current.Resources["OWLOSWarningAlpha4"]).Color; textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSWarning"]).Color); break; case 3: animation.To = Colors.Red; //((SolidColorBrush)App.Current.Resources["OWLOSDangerAlpha4"]).Color; textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSDanger"]).Color); break; default: animation.To = SystemColors.ControlTextColor; textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSSecondary"]).Color); break; } textBlock.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, animation); //https://stackoverflow.com/questions/3430659/is-there-a-wpf-typewriter-effect Storyboard story = new Storyboard { FillBehavior = FillBehavior.HoldEnd }; StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(1)) }; string tempText = string.Empty; text = DateTime.Now + " " + text; foreach (char c in text) { DiscreteStringKeyFrame discreteStringKeyFrame = new DiscreteStringKeyFrame { KeyTime = KeyTime.Paced }; tempText += c; stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame); if (tempText.Length < text.Length) { discreteStringKeyFrame.Value = tempText + "█"; } else { discreteStringKeyFrame.Value = tempText; } } Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty)); story.Children.Add(stringAnimationUsingKeyFrames); story.Begin(textBlock); } //GlobalOutLogScrollViewer.ScrollToBottom(); }); }