private static ObjectAnimationUsingKeyFrames CreateAnimation(IList <ImageSource> imageFrames) { // Initialize the animation for this object. var result = new ObjectAnimationUsingKeyFrames { Duration = s_animationDuration, }; // Creates the frames for the animation. var frameDuration = FullDuration / s_lightFrames.Value.Count; int framePoint = 0; var keyFrames = new ObjectKeyFrameCollection(); foreach (var frame in imageFrames) { var keyFrame = new DiscreteObjectKeyFrame { KeyTime = new TimeSpan(0, 0, 0, 0, framePoint), Value = frame, }; keyFrames.Add(keyFrame); framePoint += frameDuration; } result.KeyFrames = keyFrames; return(result); }
/// <summary> /// Warn user if they try to click on screenshot /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onClick(object sender, EventArgs e) { var visKeyFrames = new ObjectKeyFrameCollection { new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds(0), Value = Visibility.Visible }, new DiscreteObjectKeyFrame { KeyTime = TimeSpan.FromSeconds(2.5), Value = Visibility.Collapsed } }; var opKeyFrames = new DoubleKeyFrameCollection { new DiscreteDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(0), Value = 1 }, new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(2), Value = 1 }, new LinearDoubleKeyFrame { KeyTime = TimeSpan.FromSeconds(2.5), Value = 0 }, }; bdClick.BeginAnimation(TextBlock.VisibilityProperty, new ObjectAnimationUsingKeyFrames() { KeyFrames = visKeyFrames }); bdClick.BeginAnimation(TextBlock.OpacityProperty, new DoubleAnimationUsingKeyFrames() { KeyFrames = opKeyFrames }); }
public BasicTextEditorElement() { TextCaret = new TextCaret1() { LineHeight = 100.0, CaretWidth = 4, Name1 = "BasicTextEditorElement" }; Children.Add(TextCaret); _drawingVisual = new DrawingVisual(); Children.Insert(0, _drawingVisual); var objectKeyFrameCollection = new ObjectKeyFrameCollection() { new DiscreteObjectKeyFrame(System.Windows.Visibility.Hidden, KeyTime.FromPercent(0)), new DiscreteObjectKeyFrame(System.Windows.Visibility.Visible, KeyTime.FromPercent(0.5)) }; _blink = new ObjectAnimationUsingKeyFrames() { KeyFrames = objectKeyFrameCollection, Duration = new Duration(new TimeSpan(0, 0, 1)), RepeatBehavior = RepeatBehavior.Forever }; }
private static ObjectAnimationUsingKeyFrames GetAnimation(Image imageControl, BitmapSource source) { var cacheEntry = AnimationCache.Get(source); if (cacheEntry == null) { var decoder = GetDecoder(source, imageControl, out GifFile gifMetadata) as GifBitmapDecoder; if (decoder != null && decoder.Frames.Count > 1) { var fullSize = GetFullSize(decoder, gifMetadata); int index = 0; var keyFrames = new ObjectKeyFrameCollection(); var totalDuration = TimeSpan.Zero; BitmapSource baseFrame = null; foreach (var rawFrame in decoder.Frames) { var metadata = GetFrameMetadata(decoder, gifMetadata, index); var frame = MakeFrame(fullSize, rawFrame, metadata, baseFrame); var keyFrame = new DiscreteObjectKeyFrame(frame, totalDuration); keyFrames.Add(keyFrame); totalDuration += metadata.Delay; switch (metadata.DisposalMethod) { case FrameDisposalMethod.None: case FrameDisposalMethod.DoNotDispose: baseFrame = frame; break; case FrameDisposalMethod.RestoreBackground: if (IsFullFrame(metadata, fullSize)) { baseFrame = null; } else { baseFrame = ClearArea(frame, metadata); } break; case FrameDisposalMethod.RestorePrevious: // Reuse same base frame break; } index++; } int repeatCount = GetRepeatCountFromMetadata(decoder, gifMetadata); cacheEntry = new AnimationCacheEntry(keyFrames, totalDuration, repeatCount); AnimationCache.Add(source, cacheEntry); } } if (cacheEntry != null) { var animation = new ObjectAnimationUsingKeyFrames { KeyFrames = cacheEntry.KeyFrames, Duration = cacheEntry.Duration, RepeatBehavior = GetActualRepeatBehavior(imageControl, cacheEntry.RepeatCountFromMetadata), SpeedRatio = GetActualSpeedRatio(imageControl, cacheEntry.Duration) }; AnimationCache.AddControlForSource(source, imageControl); return(animation); } return(null); }
public AnimationCacheEntry(ObjectKeyFrameCollection keyFrames, Duration duration, int repeatCountFromMetadata) { KeyFrames = keyFrames; Duration = duration; RepeatCountFromMetadata = repeatCountFromMetadata; }