/// <summary> /// Applies a random transition effect between current and next slide show images /// </summary> private void ApplyTransitionEffect() { DoubleAnimation da = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromMilliseconds(totalAnimationPeriod / 5)), FillBehavior.HoldEnd); da.AccelerationRatio = 0.5; da.DecelerationRatio = 0.5; da.Completed += new EventHandler(this.TransitionCompleted); // Force the frame rate to animFrameRate instead of WPF's default value of 60fps. // this will reduce the CPU load on low-end machines, and will conserve battery for portable devices. Timeline.SetDesiredFrameRate(da, animFrameRate); VisualBrush vb = new VisualBrush(this._oldChild); vb.Viewbox = new Rect(0, 0, this._oldChild.ActualWidth, this._oldChild.ActualHeight); vb.ViewboxUnits = BrushMappingMode.Absolute; this._oldChild.Width = this._oldChild.ActualWidth; this._oldChild.Height = this._oldChild.ActualHeight; this._oldChild.Measure(new Size(this._oldChild.ActualWidth, this._oldChild.ActualHeight)); this._oldChild.Arrange(new Rect(0, 0, this._oldChild.ActualWidth, this._oldChild.ActualHeight)); TransitionEffect transitionEffect = GetRandomTransitionEffect(); transitionEffect.OldImage = vb; this._currentChild.Effect = transitionEffect; transitionEffect.BeginAnimation(TransitionEffect.ProgressProperty, da, HandoffBehavior.SnapshotAndReplace); }
private void MediaCenter_PreviewMouseDown(object sender, MouseButtonEventArgs e) { VisualBrush vbrush = new VisualBrush(this); _TransitionEffect = _TransitionEffect.Clone() as TransitionEffect; this.Effect = _TransitionEffect; // _TransitionEffect.Input = vbrush.Clone(); _TransitionEffect.OldImage = vbrush.Clone(); _TransitionEffect.BeginAnimation(TransitionEffect.ProgressProperty, _Animation); }
private void ApplyTransitionEffect() { TransitionEffect[] effectGroup = transitionEffects[this.rand.Next(transitionEffects.Length)]; TransitionEffect effect = effectGroup[this.rand.Next(effectGroup.Length)]; if (_useOrder) { effectGroup = transitionEffectsSingle[_nextEffect % transitionEffectsSingle.Length]; effect = effectGroup[0]; if (++_usedTimes == 2) { _usedTimes = 0; _nextEffect++; } this.effectName.Text = ExtractName(effect); if (_nextEffect == transitionEffectsSingle.Length) { _useOrder = false; this.effectName.Text = "mixed effects, random"; } } RandomizedTransitionEffect randEffect = effect as RandomizedTransitionEffect; if (randEffect != null) { randEffect.RandomSeed = this.rand.NextDouble(); } DoubleAnimation da = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(2.0)), FillBehavior.HoldEnd); da.AccelerationRatio = 0.5; da.DecelerationRatio = 0.5; da.Completed += new EventHandler(this.TransitionCompleted); effect.BeginAnimation(TransitionEffect.ProgressProperty, da); VisualBrush vb = new VisualBrush(this.oldChild); vb.Viewbox = new Rect(0, 0, this.oldChild.ActualWidth, this.oldChild.ActualHeight); vb.ViewboxUnits = BrushMappingMode.Absolute; //this.oldChild.Width = this.oldChild.ActualWidth; //this.oldChild.Height = this.oldChild.ActualHeight; //this.oldChild.Measure(new Size(this.oldChild.ActualWidth, this.oldChild.ActualHeight)); //this.oldChild.Arrange(new Rect(0, 0, this.oldChild.ActualWidth, this.oldChild.ActualHeight)); effect.OldImage = vb; this.currentChild.Effect = effect; }
private void AnimateContent(object oldContent, object newContent) { var oldContentVisual = GetVisualChild(); var tier = (RenderCapability.Tier >> 16); // if we dont have a selector, or the visual content is not a FE, do not animate if (EnableTransitions == false || ContentTransitionSelector == null || oldContentVisual == null || tier < 2) { SetNonVisualChild(newContent); return; } // create the transition TransitionEffect transitionEffect = ContentTransitionSelector.GetTransition(oldContent, newContent, this); if (transitionEffect == null) { throw new InvalidOperationException("Returned transition effect is null."); } // create the animation DoubleAnimation da = new DoubleAnimation(0.0, 1.0, new Duration(Duration), FillBehavior.HoldEnd); da.Completed += delegate { ApplyEffect(null); }; if (EasingFunction != null) { da.EasingFunction = EasingFunction; } else { da.AccelerationRatio = 0.5; da.DecelerationRatio = 0.5; } transitionEffect.BeginAnimation(TransitionEffect.ProgressProperty, da); VisualBrush oldVisualBrush = new VisualBrush(oldContentVisual); transitionEffect.OldImage = oldVisualBrush; SetNonVisualChild(newContent); ApplyEffect(transitionEffect); }