public static void Appear(FrameworkElement el, int millisecondPostpone = 0) { if (el.GetType().Name == "SplashScreenView") { el.Opacity =1.0; return; } DispatchedHandler invokedHandler = new DispatchedHandler(() => { TranslateTransform translateTransform = new TranslateTransform(); el.RenderTransform = translateTransform; translateTransform.X = (double)Animation.pixelsMove; if (translateTransform != null) { SplineDoubleKeyFrame splineDoubleKeyFrame = new SplineDoubleKeyFrame(); splineDoubleKeyFrame.KeyTime = TimeSpan.FromMilliseconds((double)(10 + millisecondPostpone)); splineDoubleKeyFrame.Value = (double)Animation.pixelsMove; SplineDoubleKeyFrame splineDoubleKeyFrame2 = new SplineDoubleKeyFrame(); splineDoubleKeyFrame2.KeyTime = TimeSpan.FromMilliseconds((double)(350 + millisecondPostpone)); splineDoubleKeyFrame2.Value = 0.0; splineDoubleKeyFrame2.KeySpline = new KeySpline(); splineDoubleKeyFrame2.KeySpline.ControlPoint1 = new Point(0.0, 0.0); splineDoubleKeyFrame2.KeySpline.ControlPoint2 = new Point(0.0, 1.0); DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(doubleAnimationUsingKeyFrames, translateTransform); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, "(TranslateTransform.X)"); doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame); doubleAnimationUsingKeyFrames.KeyFrames.Add(splineDoubleKeyFrame2); SplineDoubleKeyFrame splineDoubleKeyFrame3 = new SplineDoubleKeyFrame(); splineDoubleKeyFrame3.KeyTime = TimeSpan.FromMilliseconds((double)millisecondPostpone); splineDoubleKeyFrame3.Value = 0.0; SplineDoubleKeyFrame splineDoubleKeyFrame4 = new SplineDoubleKeyFrame(); splineDoubleKeyFrame4.KeyTime = TimeSpan.FromMilliseconds((double)(300 + millisecondPostpone)); splineDoubleKeyFrame4.Value = 1.0; DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrames2 = new DoubleAnimationUsingKeyFrames(); Storyboard.SetTarget(doubleAnimationUsingKeyFrames2, el); Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames2, "(UIElement.Opacity)"); doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame3); doubleAnimationUsingKeyFrames2.KeyFrames.Add(splineDoubleKeyFrame4); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(doubleAnimationUsingKeyFrames); storyboard.Children.Add(doubleAnimationUsingKeyFrames2); storyboard.Begin(); } }); el.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler).GetResults(); }
private Storyboard CreateEnterAnimation(Panel layoutRoot) { var enterAnimation = new Storyboard(); Storyboard.SetTarget(enterAnimation, layoutRoot); var ad = new AnimationDescription(AnimationEffect.EnterPage, AnimationEffectTarget.Primary); for (int i = 0; i < layoutRoot.Children.Count; i++) { // Add a render transform to the existing one just for animations var element = layoutRoot.Children[i]; var tg = new TransformGroup(); tg.Children.Add(new TranslateTransform()); tg.Children.Add(element.RenderTransform); element.RenderTransform = tg; // Calculate the stagger for each animation. Note that this has a max var delayMs = Math.Min(ad.StaggerDelay.TotalMilliseconds * i * ad.StaggerDelayFactor, ad.DelayLimit.Milliseconds); var delay = TimeSpan.FromMilliseconds(delayMs); foreach (var description in ad.Animations) { var animation = new DoubleAnimationUsingKeyFrames(); // Start the animation at the right offset var startSpline = new SplineDoubleKeyFrame(); startSpline.KeyTime = TimeSpan.FromMilliseconds(0); Storyboard.SetTarget(animation, element); // Hold at that offset until the stagger delay is hit var middleSpline = new SplineDoubleKeyFrame(); middleSpline.KeyTime = delay; // Animation from delayed time to last time var endSpline = new SplineDoubleKeyFrame(); endSpline.KeySpline = new KeySpline() { ControlPoint1 = description.Control1, ControlPoint2 = description.Control2 }; endSpline.KeyTime = description.Duration + delay; // Do the translation if (description.Type == PropertyAnimationType.Translation) { startSpline.Value = ANIMATION_TRANSLATION_START; middleSpline.Value = ANIMATION_TRANSLATION_START; endSpline.Value = ANIMATION_TRANSLATION_END; Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(TransformGroup.Children)[0].X"); } // Opacity else if (description.Type == PropertyAnimationType.Opacity) { startSpline.Value = ANIMATION_OPACITY_START; middleSpline.Value = ANIMATION_OPACITY_START; endSpline.Value = ANIMATION_OPACITY_END; Storyboard.SetTargetProperty(animation, "Opacity"); } else { throw new Exception("Encountered an unexpected animation type."); } // Put the final animation together animation.KeyFrames.Add(startSpline); animation.KeyFrames.Add(middleSpline); animation.KeyFrames.Add(endSpline); enterAnimation.Children.Add(animation); } } return enterAnimation; }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (mainGrid == null) { mainGrid = (Grid)GetTemplateChild("grdTile"); sbTilt = (Storyboard)mainGrid.Resources["sbTilt"]; sbHide = (Storyboard)mainGrid.Resources["sbHide"]; sbShow = (Storyboard)mainGrid.Resources["sbShow"]; sbExplode = (Storyboard)mainGrid.Resources["sbExplode"]; sbShowImage = (Storyboard)mainGrid.Resources["sbShowImage"]; recCP = (Rectangle)GetTemplateChild("recCP"); recBackground = (Rectangle)GetTemplateChild("recBackground"); recDisabled = (Rectangle)GetTemplateChild("recDisabled"); recSelected = (Rectangle)GetTemplateChild("recSelected"); lblLabel = (TextBlock)GetTemplateChild("lblLabel"); imgBackground = (Image)GetTemplateChild("imgBackground"); ccIcon = (ContentControl)GetTemplateChild("ccIcon"); ccContent = (ContentControl)GetTemplateChild("ccContent"); pthMoreItems = (Path)GetTemplateChild("pthMoreItems"); DoubleAnimationUsingKeyFrames planeProjectionRotationX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[0]; DoubleAnimationUsingKeyFrames planeProjectionRotationY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[1]; DoubleAnimationUsingKeyFrames ScaleTransformX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[2]; DoubleAnimationUsingKeyFrames ScaleTransformY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[3]; kfX = (SplineDoubleKeyFrame)planeProjectionRotationX.KeyFrames[0]; kfY = (SplineDoubleKeyFrame)planeProjectionRotationY.KeyFrames[0]; kfScaleX = (SplineDoubleKeyFrame)ScaleTransformX.KeyFrames[0]; kfScaleY = (SplineDoubleKeyFrame)ScaleTransformY.KeyFrames[0]; mainGrid.PointerMoved += mainGrid_PointerMoved; mainGrid.PointerPressed += mainGrid_PointerPressed; this.Click += TiltTile_Click; //this is what is triggered by buttonbase , pointerreleased is no longer triggered mainGrid.PointerReleased += mainGrid_PointerReleased; //may not need this since moving to ButtonBase mainGrid.PointerExited += mainGrid_PointerExited; recBackground.Fill = NormalBackground; recDisabled.Fill = DisabledBackground; recSelected.Fill = SelectedBackground; if (IsDisabled) { recDisabled.Visibility = Visibility.Visible; //mainGrid.Opacity = 0.4; } else { recDisabled.Visibility = Visibility.Collapsed; //mainGrid.Opacity = 1; } } }
private void ResetNorth( ) { Storyboard sb = new Storyboard(); sb.Duration = TimeSpan.FromMilliseconds(500.0); DoubleAnimationUsingKeyFrames frames= new DoubleAnimationUsingKeyFrames(); SplineDoubleKeyFrame frame2 = new SplineDoubleKeyFrame(); frame2.KeyTime = sb.Duration.TimeSpan; frame2.Value = 0.0; KeySpline spline = new KeySpline(); spline.ControlPoint1 = new Point(0.0 , 0.1); spline.ControlPoint2 = new Point(0.1 , 1.0); frame2.KeySpline = spline; SplineDoubleKeyFrame frame = frame2; frames.KeyFrames.Add(frame); if (this.Map.Angle > 180) { frame.Value = 360.0; }//正转到北 if (this.Map.Angle <= 180) { frame.Value = 0.0; }//转回去 frames.SetValue(Storyboard.TargetPropertyProperty , "Angle"); sb.Children.Add(frames); Storyboard.SetTarget(frames , this.Map); sb.Begin(); }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (mainGrid == null) { mainGrid = (Grid)GetTemplateChild("grdTile"); sbTilt = (Storyboard)mainGrid.Resources["sbTilt"]; sbHide = (Storyboard)mainGrid.Resources["sbHide"]; sbShow = (Storyboard)mainGrid.Resources["sbShow"]; sbExplode = (Storyboard)mainGrid.Resources["sbExplode"]; recCP = (Rectangle)GetTemplateChild("recCP"); recBackground = (Rectangle)GetTemplateChild("recBackground"); recDisabled = (Rectangle)GetTemplateChild("recDisabled"); lblLabel = (TextBlock)GetTemplateChild("lblLabel"); imgBackground = (Image)GetTemplateChild("imgBackground"); DoubleAnimationUsingKeyFrames planeProjectionRotationX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[0]; DoubleAnimationUsingKeyFrames planeProjectionRotationY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[1]; DoubleAnimationUsingKeyFrames ScaleTransformX = (DoubleAnimationUsingKeyFrames)sbTilt.Children[2]; DoubleAnimationUsingKeyFrames ScaleTransformY = (DoubleAnimationUsingKeyFrames)sbTilt.Children[3]; kfX = (SplineDoubleKeyFrame)planeProjectionRotationX.KeyFrames[0]; kfY = (SplineDoubleKeyFrame)planeProjectionRotationY.KeyFrames[0]; kfScaleX = (SplineDoubleKeyFrame)ScaleTransformX.KeyFrames[0]; kfScaleY = (SplineDoubleKeyFrame)ScaleTransformY.KeyFrames[0]; mainGrid.PointerMoved += mainGrid_PointerMoved; mainGrid.PointerPressed +=mainGrid_PointerPressed; mainGrid.PointerReleased += mainGrid_PointerReleased; mainGrid.PointerExited += mainGrid_PointerExited; recBackground.Fill = NormalBackground; recDisabled.Fill = DisabledBackground; if (IsDisabled) { recDisabled.Visibility = Visibility.Visible; //mainGrid.Opacity = 0.4; } else { recDisabled.Visibility = Visibility.Collapsed; //mainGrid.Opacity = 1; } } }