private static DoubleAnimation CreateRotationAnimation(RotationDef rd) { DoubleAnimation rotateAnimation = new DoubleAnimation(); rotateAnimation.BeginTime = new TimeSpan(0); rotateAnimation.Duration = new TimeSpan(rd.AnimationDuration.TimeSpan.Ticks); rotateAnimation.From = rd.FromDegrees; rotateAnimation.To = rd.ToDegrees; rotateAnimation.EasingFunction = new QuarticEase() { EasingMode = System.Windows.Media.Animation.EasingMode.EaseInOut }; Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath(rd.RotationProperty)); Storyboard.SetTarget(rotateAnimation, rd.PlaneProjection); return(rotateAnimation); }
private static DoubleAnimation CreateRotationAnimation(RotationDef rd) { DoubleAnimation rotateAnimation = new DoubleAnimation(); rotateAnimation.BeginTime = new TimeSpan(0); rotateAnimation.Duration = new TimeSpan(rd.AnimationDuration.TimeSpan.Ticks); rotateAnimation.From = rd.FromDegrees; rotateAnimation.To = rd.ToDegrees; rotateAnimation.EasingFunction = new QuarticEase() { EasingMode = System.Windows.Media.Animation.EasingMode.EaseInOut }; Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath(rd.RotationProperty)); Storyboard.SetTarget(rotateAnimation, rd.PlaneProjection); return rotateAnimation; }
private void StartAnimation() { bool isHitTestVisible = true; try { if (SourceElement != null) { isHitTestVisible = SourceElement.IsHitTestVisible; SourceElement.IsHitTestVisible = false; } Projection frontBackup = null; Projection backBackup = null; if (FrontElement == null || BackElement == null) { return; } //Backup in case projections are used if (FrontElement.Projection != null) { frontBackup = FrontElement.Projection; } if (BackElement.Projection != null) { backBackup = BackElement.Projection; } FrontElement.Projection = null; BackElement.Projection = null; FrontElement.Projection = new PlaneProjection() { CenterOfRotationY = .5 }; FrontElement.RenderTransformOrigin = new Point(.5, .5); FrontElement.Opacity = 0; BackElement.Projection = new PlaneProjection() { CenterOfRotationY = .5, RotationY = 180.0 }; BackElement.RenderTransformOrigin = new Point(.5, .5); BackElement.Opacity = 0; RotationDef showBackRotation = null; RotationDef hideFrontRotation = null; var frontPP = new PlaneProjection(); var backPP = new PlaneProjection(); switch (Rotation) { case RotationDirection.LeftToRight: backPP.CenterOfRotationY = frontPP.CenterOfRotationY = 0.5; showBackRotation = new RotationDef { FromDegrees = 180.0, MidDegrees = 90.0, ToDegrees = 0.0, RotationProperty = "RotationY", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = -90.0, ToDegrees = -180.0, RotationProperty = "RotationY", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.RightToLeft: backPP.CenterOfRotationY = frontPP.CenterOfRotationY = 0.5; showBackRotation = new RotationDef { FromDegrees = -180.0, MidDegrees = -90.0, ToDegrees = 0.0, RotationProperty = "RotationY", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = 90.0, ToDegrees = 180.0, RotationProperty = "RotationY", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.BottomToTop: backPP.CenterOfRotationX = frontPP.CenterOfRotationX = 0.5; showBackRotation = new RotationDef { FromDegrees = 180.0, MidDegrees = 90.0, ToDegrees = 0.0, RotationProperty = "RotationX", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = -90.0, ToDegrees = -180.0, RotationProperty = "RotationX", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.TopToBottom: backPP.CenterOfRotationX = frontPP.CenterOfRotationX = 0.5; showBackRotation = new RotationDef { FromDegrees = -180.0, MidDegrees = -90.0, ToDegrees = 0.0, RotationProperty = "RotationX", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = 90.0, ToDegrees = 180.0, RotationProperty = "RotationX", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; } FrontElement.RenderTransformOrigin = new Point(.5, .5); BackElement.RenderTransformOrigin = new Point(.5, .5); FrontElement.Projection = frontPP; BackElement.Projection = backPP; Storyboard frontToBackStoryboard = new Storyboard() { Duration = this.Duration }; // Rotation frontToBackStoryboard.Children.Add(CreateRotationAnimation(showBackRotation)); frontToBackStoryboard.Children.Add(CreateRotationAnimation(hideFrontRotation)); // Visibility frontToBackStoryboard.Children.Add(CreateVisibilityAnimation(showBackRotation.AnimationDuration, FrontElement, false)); frontToBackStoryboard.Children.Add(CreateVisibilityAnimation(hideFrontRotation.AnimationDuration, BackElement, true)); frontToBackStoryboard.Begin(); frontToBackStoryboard.Completed += (o, e) => { if (SourceElement != null) { SourceElement.IsHitTestVisible = isHitTestVisible; } OnStoryboardCompleted(); }; } catch { if (SourceElement != null) { SourceElement.IsHitTestVisible = isHitTestVisible; } } }
private void StartAnimation() { bool isHitTestVisible = true; try { if (SourceElement != null) { isHitTestVisible = SourceElement.IsHitTestVisible; SourceElement.IsHitTestVisible = false; } Projection frontBackup = null; Projection backBackup = null; if (FrontElement == null || BackElement == null) return; //Backup in case projections are used if (FrontElement.Projection != null) frontBackup = FrontElement.Projection; if (BackElement.Projection != null) backBackup = BackElement.Projection; FrontElement.Projection = null; BackElement.Projection = null; FrontElement.Projection = new PlaneProjection() { CenterOfRotationY = .5 }; FrontElement.RenderTransformOrigin = new Point(.5, .5); FrontElement.Opacity = 0; BackElement.Projection = new PlaneProjection() { CenterOfRotationY = .5, RotationY = 180.0 }; BackElement.RenderTransformOrigin = new Point(.5, .5); BackElement.Opacity = 0; RotationDef showBackRotation = null; RotationDef hideFrontRotation = null; var frontPP = new PlaneProjection(); var backPP = new PlaneProjection(); switch (Rotation) { case RotationDirection.LeftToRight: backPP.CenterOfRotationY = frontPP.CenterOfRotationY = 0.5; showBackRotation = new RotationDef { FromDegrees = 180.0, MidDegrees = 90.0, ToDegrees = 0.0, RotationProperty = "RotationY", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = -90.0, ToDegrees = -180.0, RotationProperty = "RotationY", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.RightToLeft: backPP.CenterOfRotationY = frontPP.CenterOfRotationY = 0.5; showBackRotation = new RotationDef { FromDegrees = -180.0, MidDegrees = -90.0, ToDegrees = 0.0, RotationProperty = "RotationY", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = 90.0, ToDegrees = 180.0, RotationProperty = "RotationY", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.BottomToTop: backPP.CenterOfRotationX = frontPP.CenterOfRotationX = 0.5; showBackRotation = new RotationDef { FromDegrees = 180.0, MidDegrees = 90.0, ToDegrees = 0.0, RotationProperty = "RotationX", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = -90.0, ToDegrees = -180.0, RotationProperty = "RotationX", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; case RotationDirection.TopToBottom: backPP.CenterOfRotationX = frontPP.CenterOfRotationX = 0.5; showBackRotation = new RotationDef { FromDegrees = -180.0, MidDegrees = -90.0, ToDegrees = 0.0, RotationProperty = "RotationX", PlaneProjection = backPP, AnimationDuration = this.Duration }; hideFrontRotation = new RotationDef { FromDegrees = 0.0, MidDegrees = 90.0, ToDegrees = 180.0, RotationProperty = "RotationX", PlaneProjection = frontPP, AnimationDuration = this.Duration }; break; } FrontElement.RenderTransformOrigin = new Point(.5, .5); BackElement.RenderTransformOrigin = new Point(.5, .5); FrontElement.Projection = frontPP; BackElement.Projection = backPP; Storyboard frontToBackStoryboard = new Storyboard() { Duration = this.Duration }; // Rotation frontToBackStoryboard.Children.Add(CreateRotationAnimation(showBackRotation)); frontToBackStoryboard.Children.Add(CreateRotationAnimation(hideFrontRotation)); // Visibility frontToBackStoryboard.Children.Add(CreateVisibilityAnimation(showBackRotation.AnimationDuration, FrontElement, false)); frontToBackStoryboard.Children.Add(CreateVisibilityAnimation(hideFrontRotation.AnimationDuration, BackElement, true)); frontToBackStoryboard.Begin(); frontToBackStoryboard.Completed += (o, e) => { if (SourceElement != null) SourceElement.IsHitTestVisible = isHitTestVisible; OnStoryboardCompleted(); }; } catch { if (SourceElement != null) SourceElement.IsHitTestVisible = isHitTestVisible; } }