/// <summary> /// Helper used by the four Freezable clone methods to copy the resolved key times and /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here. /// </summary> /// <param name="sourceAnimation"></param> /// <param name="isCurrentValueClone"></param> private void CopyCommon(StringAnimationUsingKeyFrames sourceAnimation, bool isCurrentValueClone) { _areKeyTimesValid = sourceAnimation._areKeyTimesValid; if (_areKeyTimesValid && sourceAnimation._sortedResolvedKeyFrames != null) { // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceAnimation._sortedResolvedKeyFrames.Clone(); } if (sourceAnimation._keyFrames != null) { if (isCurrentValueClone) { _keyFrames = (StringKeyFrameCollection)sourceAnimation._keyFrames.CloneCurrentValue(); } else { _keyFrames = (StringKeyFrameCollection)sourceAnimation._keyFrames.Clone(); } OnFreezablePropertyChanged(null, _keyFrames); } }
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); }
/// <summary> /// Implementation of <see cref="System.Windows.Freezable.CloneCore(System.Windows.Freezable)">Freezable.CloneCore</see>. /// </summary> protected override void CloneCore(Freezable sourceFreezable) { StringAnimationUsingKeyFrames sourceAnimation = (StringAnimationUsingKeyFrames)sourceFreezable; base.CloneCore(sourceFreezable); CopyCommon(sourceAnimation, /* isCurrentValueClone = */ false); }
/// <summary> /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>. /// </summary> protected override void GetCurrentValueAsFrozenCore(Freezable source) { StringAnimationUsingKeyFrames sourceAnimation = (StringAnimationUsingKeyFrames)source; base.GetCurrentValueAsFrozenCore(source); CopyCommon(sourceAnimation, /* isCurrentValueClone = */ true); }
void StartCursorAnimation() { var ani = new StringAnimationUsingKeyFrames() { Duration=new Duration(TimeSpan.FromMilliseconds(1000)) }; ani.KeyFrames.Add(new DiscreteStringKeyFrame() { Value = "", KeyTime=KeyTime.FromPercent(0) }); ani.KeyFrames.Add(new DiscreteStringKeyFrame() { Value = " ", KeyTime = KeyTime.FromPercent(0.5) }); ani.RepeatBehavior = RepeatBehavior.Forever; _consolePostCursor.BeginAnimation(TextBlock.TextProperty, ani); }
/// <summary> /// Helper used by the four Freezable clone methods to copy the resolved key times and /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here. /// </summary> /// <param name="sourceAnimation"></param> /// <param name="isCurrentValueClone"></param> private void CopyCommon(StringAnimationUsingKeyFrames sourceAnimation, bool isCurrentValueClone) { _areKeyTimesValid = sourceAnimation._areKeyTimesValid; if ( _areKeyTimesValid && sourceAnimation._sortedResolvedKeyFrames != null) { // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceAnimation._sortedResolvedKeyFrames.Clone(); } if (sourceAnimation._keyFrames != null) { if (isCurrentValueClone) { _keyFrames = (StringKeyFrameCollection)sourceAnimation._keyFrames.CloneCurrentValue(); } else { _keyFrames = (StringKeyFrameCollection)sourceAnimation._keyFrames.Clone(); } OnFreezablePropertyChanged(null, _keyFrames); } }
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); }
/// <summary> /// 在指定的文字层绑定控件上进行打字动画 /// </summary> /// <param name="id">层id</param> /// <param name="orgString">原字符串</param> /// <param name="appendString">要追加的字符串</param> /// <param name="msglayBinding">文字层的控件</param> /// <param name="wordTimeSpan">字符之间的打字时间间隔</param> private void TypeWriter(int id, string orgString, string appendString, TextBlock msglayBinding, int wordTimeSpan) { this.HideMessageTria(); Storyboard MsgLayerTypingStory = new Storyboard(); DiscreteStringKeyFrame discreteStringKeyFrame; 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) { 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 += new EventHandler(this.TypeWriterAnimationCompletedCallback); MsgLayerTypingStory.Begin(); this.MsgStoryboardDict[id] = MsgLayerTypingStory; }
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); }