public void Anim_Closing() { AssociatedObject.RenderTransformOrigin = new Point { X = 0.5, Y = 0.5 }; ScaleTransform = AssociatedObject.FindName("MScaleTransform") as ScaleTransform; ScaleTransform?.BeginAnimation(ScaleTransform.ScaleXProperty, CloseAnimation.Clone()); ScaleTransform?.BeginAnimation(ScaleTransform.ScaleYProperty, CloseAnimation.Clone()); AssociatedObject.BeginAnimation(UIElement.OpacityProperty, CloseAnimation); }
/// <summary> /// Scale /// </summary> /// <param name="fromX"></param> /// <param name="toX"></param> /// <param name="fromY"></param> /// <param name="toY"></param> /// <param name="milliSeconds"></param> /// <param name="elem"></param> /// <param name="decelerationRatio"></param> /// <returns></returns> public static async Task ElementScale(double fromX, double toX, double fromY, double toY, float milliSeconds, FrameworkElement elem) { try { var sb = new Storyboard(); var animationX = new DoubleAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(milliSeconds)), From = fromX, To = toX, EasingFunction = new QuinticEase() }; var animationY = new DoubleAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(milliSeconds)), From = fromY, To = toY, EasingFunction = new QuinticEase() }; var lt = new ScaleTransform(fromX, fromY); elem.LayoutTransform = lt; lt.BeginAnimation(ScaleTransform.ScaleXProperty, animationX); lt.BeginAnimation(ScaleTransform.ScaleYProperty, animationY); await Task.Delay((int)milliSeconds); } catch (Exception) { throw; } }
private void swingAnimation(string screenPosition) { TransformGroup springAnimationTransformGroup = new TransformGroup(); ScaleTransform springAnimationScaleTransformGroup = new ScaleTransform(); springAnimationScaleTransformGroup.CenterX = this.Width / 2; springAnimationScaleTransformGroup.CenterY = this.Height / 2; springAnimationTransformGroup.Children.Add(springAnimationScaleTransformGroup); this.RenderTransform = springAnimationScaleTransformGroup; DoubleAnimation springDoubleAnimation = new DoubleAnimation(); springDoubleAnimation.From = 1; springDoubleAnimation.To = 1.5; springDoubleAnimation.AutoReverse = true; springDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); DoubleAnimation jumpDoubleAnimation = new DoubleAnimation(); jumpDoubleAnimation.From = STANDARD_ICON_DIMENSION; jumpDoubleAnimation.To = STANDARD_ICON_DIMENSION * 2; jumpDoubleAnimation.AutoReverse = true; jumpDoubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); if ((screenPosition == "Top") | (screenPosition == "Bottom")) { springAnimationScaleTransformGroup.BeginAnimation(ScaleTransform.ScaleXProperty, springDoubleAnimation); this.BeginAnimation(AnimatedIcon.HeightProperty, jumpDoubleAnimation); } else { springAnimationScaleTransformGroup.BeginAnimation(ScaleTransform.ScaleYProperty, springDoubleAnimation); this.BeginAnimation(AnimatedIcon.WidthProperty, jumpDoubleAnimation); } }
public void EllipseMousedown(object sender, MouseButtonEventArgs e) { Ellipse temp = (Ellipse)e.Source; ScaleTransform scale = new ScaleTransform(); scale.CenterX = 3; scale.CenterY = 3; temp.RenderTransform = scale; double startNum = 1; double endNum = 10; DoubleAnimation growAnimation = new DoubleAnimation(); growAnimation.Duration = TimeSpan.FromSeconds(5); growAnimation.From = startNum; growAnimation.To = endNum; growAnimation.AutoReverse = true; temp.RenderTransform = scale; scale.BeginAnimation(ScaleTransform.ScaleXProperty, growAnimation); scale.BeginAnimation(ScaleTransform.ScaleYProperty, growAnimation); }
private void KillGCP(GraphContentPresenter gcp, bool isCenter) { Debug.Assert(VisualTreeHelper.GetParent(gcp) == this); this.InvalidateVisual(); _fadingGCPs.Add(_fadingGCPsNextKey, gcp); _fadingGCPListValid = false; _isChildCountValid = false; int theKey = _fadingGCPsNextKey; gcp.IsHitTestVisible = false; if (isCenter) { gcp.WasCenter = true; } ScaleTransform st = gcp.ScaleTransform; DoubleAnimation da = GetNewHideAnimation(gcp, this, theKey); st.BeginAnimation(ScaleTransform.ScaleXProperty, da); st.BeginAnimation(ScaleTransform.ScaleYProperty, da); gcp.BeginAnimation(OpacityProperty, da); if (_fadingGCPsNextKey == int.MaxValue) { _fadingGCPsNextKey = int.MinValue; } else { _fadingGCPsNextKey++; } }
/* * 4右侧拉伸 */ public static void ScaleXMoveOut(Border CoverBorder) { CoverBorder.RenderTransformOrigin = new System.Windows.Point(1.0, 0.5); TransformGroup group = new TransformGroup(); CoverBorder.RenderTransform = group; ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = new DoubleAnimation(1.0, 0, new Duration(TimeSpan.FromMilliseconds(500))); da.BeginTime = TimeSpan.FromMilliseconds(0); //da.EasingFunction = easingFunction; da.Completed += (sender1, e1) => CoverBorderMoveOut_Completed(CoverBorder); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); }
/// <summary> /// 控件窗口消失动画 /// </summary> public static void UIElementGo(UIElement uIElement, ScaleTransform _scale) { PennerDoubleAnimation da = new PennerDoubleAnimation() { From = 1, To = 0.9, Equation = Equations.BackEaseIn, FillBehavior = FillBehavior.Stop, Duration = TimeSpan.FromSeconds(0.5) }; da.Completed += delegate { _scale.ScaleX = 1; _scale.ScaleY = 1; }; DoubleAnimation daO = new DoubleAnimation() { From = 1, To = 0, FillBehavior = FillBehavior.Stop, Duration = TimeSpan.FromSeconds(0.5) }; daO.Completed += delegate { uIElement.Opacity = 0; if (UIElementGoFinished != null) { UIElementGoFinished(uIElement, new EventArgs()); } }; _scale.BeginAnimation(ScaleTransform.ScaleXProperty, da); _scale.BeginAnimation(ScaleTransform.ScaleYProperty, da); uIElement.BeginAnimation(UIElement.OpacityProperty, daO); }
public MainWindow() { InitializeComponent(); ScaleTransform transormFast = new ScaleTransform(); ScaleTransform transformSlow = new ScaleTransform(); DoubleAnimation fastAnim = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(1000)); DoubleAnimation slowAnim = new DoubleAnimation(0.3, 1, TimeSpan.FromMilliseconds(1000)); transormFast.BeginAnimation(ScaleTransform.ScaleYProperty, fastAnim); transformSlow.BeginAnimation(ScaleTransform.ScaleYProperty, slowAnim); CitiesPanel.RenderTransform = transormFast; HourlyPanel.RenderTransform = transformSlow; DailyPanel.RenderTransform = transformSlow; }
private void AnimateSiteScaleTransform(WidgetSiteControl site, ref TimeSpan beginTime, double fromScale, double toScale, EventHandler completedCallback) { ScaleTransform transform = (ScaleTransform)((TransformGroup)site.RenderTransform).Children[0]; if (fromScale == double.NaN) { transform.BeginAnimation(ScaleTransform.ScaleXProperty, null); transform.BeginAnimation(ScaleTransform.ScaleYProperty, null); } else { AnimationTimeline animation = BuildSiteScaleAnimation(beginTime, fromScale, toScale); if (completedCallback != null) { animation.Completed += completedCallback; } transform.BeginAnimation(ScaleTransform.ScaleXProperty, animation); transform.BeginAnimation(ScaleTransform.ScaleYProperty, BuildSiteScaleAnimation(beginTime, fromScale, toScale)); } }
/// <summary>Zoom into or out of the content.</summary> /// <param name="deltaZoom">Factor to mutliply the zoom level by. </param> /// <param name="mousePosition">Logical mouse position relative to the original content.</param> /// <param name="physicalPosition">Actual mouse position on the screen (relative to the parent window)</param> public void DoZoom(double deltaZoom, Point mousePosition, Point physicalPosition) { // Keep Zoom within bounds declared by Minimum/MaximumZoom double currentZoom = zoomTransform.ScaleX; currentZoom *= deltaZoom; if (currentZoom < MinimumZoom) { currentZoom = MinimumZoom; } else if (currentZoom > MaximumZoom) { currentZoom = MaximumZoom; } translateTransform.BeginAnimation(TranslateTransform.XProperty, CreateZoomAnimation(-1 * (mousePosition.X * currentZoom - physicalPosition.X))); translateTransform.BeginAnimation(TranslateTransform.YProperty, CreateZoomAnimation(-1 * (mousePosition.Y * currentZoom - physicalPosition.Y))); zoomTransform.BeginAnimation(ScaleTransform.ScaleXProperty, CreateZoomAnimation(currentZoom)); zoomTransform.BeginAnimation(ScaleTransform.ScaleYProperty, CreateZoomAnimation(currentZoom)); }
private void FlipCardRectangle(Rectangle cardRectangle, int from, int to) { cardRectangle.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform flipTrans = new ScaleTransform(); flipTrans.ScaleY = 1; cardRectangle.RenderTransform = flipTrans; DoubleAnimation da = new DoubleAnimation(); da.From = from; da.To = to; da.Duration = TimeSpan.FromMilliseconds(200); flipTrans.BeginAnimation(ScaleTransform.ScaleYProperty, da); }
private void StartAnimation() { if (_Transformer != null) { double V = Math.Min(Math.Max(0, Value), 100); if (V > 0) { V = V / 100; } DoubleAnimation DA = new DoubleAnimation(V, new Duration(TimeSpan.FromMilliseconds(AnimationDuration))); DA.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseInOut, Exponent = 2 }; _Transformer.BeginAnimation(ScaleTransform.ScaleXProperty, DA); } }
//Roam Animation private void roamAnimate(Node n) { Point target = getPoint(n.Level, n); DoubleAnimation rotA; DoubleAnimation xA = new DoubleAnimation(n.RenderTransform.Value.OffsetX, target.X, new TimeSpan(0, 0, 0, 0, 3000)); DoubleAnimation yA = new DoubleAnimation(n.RenderTransform.Value.OffsetY, target.Y, new TimeSpan(0, 0, 0, 0, 3000)); DoubleAnimation sA; if (n.RenderTransform.Value.M11 <= 1.5) { rotA = new DoubleAnimation(0, 360, new TimeSpan(0, 0, 0, 0, 3000)); sA = new DoubleAnimation(1, 2, new TimeSpan(0, 0, 0, 0, 3000)); } else { rotA = new DoubleAnimation(360, 0, new TimeSpan(0, 0, 0, 0, 3000)); sA = new DoubleAnimation(2, 1, new TimeSpan(0, 0, 0, 0, 3000)); } n.Tag = rotA; rotA.Completed += new EventHandler(yA_Completed); TransformGroup tg = new TransformGroup(); RotateTransform rt = new RotateTransform(); TranslateTransform xtt = new TranslateTransform(); TranslateTransform ytt = new TranslateTransform(); ScaleTransform xst = new ScaleTransform(); ScaleTransform yst = new ScaleTransform(); tg.Children.Add(rt); tg.Children.Add(xst); tg.Children.Add(yst); tg.Children.Add(xtt); tg.Children.Add(ytt); n.AllowResize = false; n.RenderTransform = tg; n.RenderTransformOrigin = new Point(0.5, 0.5); rt.BeginAnimation(RotateTransform.AngleProperty, rotA); xtt.BeginAnimation(TranslateTransform.XProperty, xA); ytt.BeginAnimation(TranslateTransform.YProperty, yA); xst.BeginAnimation(ScaleTransform.ScaleXProperty, sA); yst.BeginAnimation(ScaleTransform.ScaleYProperty, sA); }
private void OnMouseDown(object Sender, MouseButtonEventArgs E) { if (IsSelected) { return; } IsSelected = true; SelectSyncAction?.Invoke(this.Skill); Container.Background = new SolidColorBrush(Color.FromArgb(136, 30, 144, 255)); ScaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimationUsingKeyFrames() { KeyFrames = new DoubleKeyFrameCollection() { new EasingDoubleKeyFrame(0.9, TimeSpan.FromSeconds(0.2), new ExponentialEase() { EasingMode = EasingMode.EaseInOut }), new EasingDoubleKeyFrame(1, TimeSpan.FromSeconds(0.4), new ExponentialEase() { EasingMode = EasingMode.EaseInOut }), } }); ScaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimationUsingKeyFrames() { KeyFrames = new DoubleKeyFrameCollection() { new EasingDoubleKeyFrame(0.9, TimeSpan.FromSeconds(0.2), new ExponentialEase() { EasingMode = EasingMode.EaseInOut }), new EasingDoubleKeyFrame(1, TimeSpan.FromSeconds(0.4), new ExponentialEase() { EasingMode = EasingMode.EaseInOut }), } }); }
/// <summary> /// Maybe Im just an idiot but this is awfuly hard to do in WPF /// </summary> private void doCircularCursorAnimation() { double scaleFactor = 58.0 / 2.0; double baseTimeInterval = GlobalConfiguration.cursorGeneralActivationMS / 4.0; // Awesome one time instantiation of all this crazy junk if (size1 == null) { size1 = new DoubleAnimation(1, scaleFactor, new Duration(TimeSpan.FromMilliseconds(baseTimeInterval))); size2 = new DoubleAnimation(1, scaleFactor, new Duration(TimeSpan.FromMilliseconds(baseTimeInterval))); //size2.BeginTime = TimeSpan.FromMilliseconds(baseTimeInterval); size3 = new DoubleAnimation(1, scaleFactor, new Duration(TimeSpan.FromMilliseconds(baseTimeInterval))); //size3.BeginTime = TimeSpan.FromMilliseconds((baseTimeInterval * 2)); size4 = new DoubleAnimation(1, scaleFactor, new Duration(TimeSpan.FromMilliseconds(baseTimeInterval))); //size4.BeginTime = TimeSpan.FromMilliseconds((baseTimeInterval * 3)); scaleTransform1 = new ScaleTransform(1, 1, 0, 0); scaleTransform2 = new ScaleTransform(1, 1, 58, 0); scaleTransform3 = new ScaleTransform(1, 1, 58, 58); scaleTransform4 = new ScaleTransform(1, 1, 58, 58); } destroyCircleTransitionElements(); scaleTransform1 = new ScaleTransform(1, 1, 0, 0); scaleTransform2 = new ScaleTransform(1, 1, 58, 0); scaleTransform3 = new ScaleTransform(1, 1, 58, 58); scaleTransform4 = new ScaleTransform(1, 1, 58, 58); rotateTransform4 = new RotateTransform(180, 58, 87); group4 = new TransformGroup(); group4.Children.Add(rotateTransform4); group4.Children.Add(scaleTransform4); clip1 = new RectangleGeometry(new Rect(0.0, 0.0, 2.0, 58.0)); circChunkContainer.Children.Add(clip1); clip1.Transform = scaleTransform1; size1.Completed += handleSetp1Done; scaleTransform1.BeginAnimation(ScaleTransform.ScaleXProperty, size1); }
//Scale Animation private void scaleAnimate(Node Smile) { Smile.RenderTransformOrigin = new Point(0, 0); DoubleAnimation scaleA = new DoubleAnimation(1, 2, new TimeSpan(0, 0, 0, 0, 1000)); scaleA.AutoReverse = true; scaleA.RepeatBehavior = RepeatBehavior.Forever; TransformGroup tg = new TransformGroup(); ScaleTransform xst = new ScaleTransform(); xst.CenterX = 25; xst.CenterY = 25; ScaleTransform yst = new ScaleTransform(); yst.CenterX = 25; yst.CenterY = 25; tg.Children.Add(xst); tg.Children.Add(yst); Smile.AllowResize = false; Smile.RenderTransform = tg; xst.BeginAnimation(ScaleTransform.ScaleXProperty, scaleA); yst.BeginAnimation(ScaleTransform.ScaleYProperty, scaleA); }
private void _BeginAnimateContentReplacement() { var flapTransformTop = new ScaleTransform { CenterY = _rectangleTop.ActualHeight / 2 }; _rectangleTop.RenderTransform = flapTransformTop; var flapTransformBottom = new ScaleTransform { CenterY = _rectangleBottom.ActualHeight / 2 }; _rectangleBottom.RenderTransform = flapTransformBottom; _rectangleTop.Visibility = Visibility.Visible; _rectangleBottom.Visibility = Visibility.Visible; _rectangleBottomStatic.Visibility = Visibility.Visible; IEasingFunction ease = null;//new BackEase() { EasingMode = EasingMode.EaseOut }; AnimationTimeline animationTop = AnimateLib.CreateAnimation(1, 0, 0, 0.1, null, (object s, EventArgs e) => { _rectangleTop.Visibility = Visibility.Hidden; _rectangleBottom.Visibility = Visibility.Visible; _rectangleBottom.Fill = AnimateLib.CreateBrushFromVisual(_displayBottom, (int)_rectangleBottom.ActualWidth, (int)_rectangleBottom.ActualHeight); }); AnimationTimeline animationBottom = AnimateLib.CreateAnimation(0, 1, 0.1, 0.1, ease, (object s, EventArgs e) => { _rectangleBottom.Visibility = Visibility.Hidden; _rectangleBottomStatic.Visibility = Visibility.Hidden; }); flapTransformTop.BeginAnimation(ScaleTransform.ScaleYProperty, animationTop, HandoffBehavior.SnapshotAndReplace); flapTransformBottom.BeginAnimation(ScaleTransform.ScaleYProperty, animationBottom, HandoffBehavior.SnapshotAndReplace); }
private void ChangeCity(object sender, RoutedEventArgs e) { ScaleTransform transformSlow = new ScaleTransform(); DoubleAnimation slowAnim = new DoubleAnimation(0.3, 1, TimeSpan.FromMilliseconds(500)); transformSlow.BeginAnimation(ScaleTransform.ScaleYProperty, slowAnim); HourlyPanel.RenderTransform = transformSlow; DailyPanel.RenderTransform = transformSlow; var citiesButtons = CitiesPanel.Children; foreach (Button cityButton in citiesButtons) { cityButton.Background = Brushes.PaleGreen; } LinearGradientBrush gradientBg = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(1, 0), GradientStops = new GradientStopCollection { new GradientStop { Color = Colors.PaleGreen, Offset = 0 }, new GradientStop { Color = Colors.Cyan, Offset = 1 } } }; Button clickedButton = sender as Button; clickedButton.Background = gradientBg; }
// 20120614 mod 加入动画 private void Expander_Expanded(object sender, RoutedEventArgs e) { foreach (var child in (LayoutRoot.Content as StackPanel).Children) { var exp = child as Expander; if (exp != null) { if (sender != exp) { if (exp.IsExpanded == true) { var content = exp.Content as FrameworkElement; if (content != null) { var trans = new ScaleTransform(1, 1); content.LayoutTransform = trans; DoubleAnimation da = new DoubleAnimation(0, new Duration(TimeSpan.Parse("0:0:0.2"))); da.Completed += (s, args) => exp.IsExpanded = false; trans.BeginAnimation(ScaleTransform.ScaleYProperty, da); } } } else { var content = exp.Content as FrameworkElement; if (content != null) { var trans = new ScaleTransform(1, 0); content.LayoutTransform = trans; DoubleAnimation da = new DoubleAnimation(1, new Duration(TimeSpan.Parse("0:0:0.4"))); trans.BeginAnimation(ScaleTransform.ScaleYProperty, da); } } } } }
public static void Animate(this WidgetView view, AnimationMode animationMode, bool focus = false, Action astartAction = null, Action aendAction = null, bool?isDocked = null, HorizontalAlignment?dockHorizontalAlignment = null, VerticalAlignment?dockVerticalAlignment = null) { var settings = view.Id.GetSettings(); var horizontalAlignment = dockHorizontalAlignment ?? settings.HorizontalAlignment; var verticalAlignment = dockVerticalAlignment ?? settings.VerticalAlignment; var docked = isDocked ?? settings.IsDocked; view.RenderTransformOrigin = new Point(0.5, 0.5); if (docked) { switch (horizontalAlignment) { case HorizontalAlignment.Left: view.RenderTransformOrigin = new Point(0, view.RenderTransformOrigin.Y); break; case HorizontalAlignment.Right: view.RenderTransformOrigin = new Point(1, view.RenderTransformOrigin.Y); break; } switch (verticalAlignment) { case VerticalAlignment.Top: view.RenderTransformOrigin = new Point(view.RenderTransformOrigin.X, 0); break; case VerticalAlignment.Bottom: view.RenderTransformOrigin = new Point(view.RenderTransformOrigin.X, 1); break; } } Action startAction = delegate { if (animationMode == AnimationMode.Show) { view.Show(); } astartAction?.Invoke(); view.AnimationRunning = true; }; Action finishAction = delegate { if (animationMode == AnimationMode.Hide) { view.Hide(); } else { if (focus && view.Settings.RefocusMainElementOnShow) { view.FocusMainElement(); } } aendAction?.Invoke(); view.AnimationRunning = false; }; if (settings.Style.AnimationType == AnimationType.None) { startAction(); finishAction(); return; } var doubleAnimation = new DoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(settings.Style.AnimationTime)), From = animationMode == AnimationMode.Show ? 0 : 1, To = animationMode == AnimationMode.Show ? 1 : 0, FillBehavior = FillBehavior.Stop, EasingFunction = settings.Style.AnimationEase ? new SineEase { EasingMode = animationMode == AnimationMode.Show ? EasingMode.EaseIn : EasingMode.EaseOut } : null }; // Start animation. startAction(); switch (settings.Style.AnimationType) { case AnimationType.Fade: var storyBoard = new Storyboard(); storyBoard.Completed += (sender, args) => finishAction(); storyBoard.Children.Add(doubleAnimation); Storyboard.SetTarget(doubleAnimation, view); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(UIElement.OpacityProperty)); storyBoard.Begin(); break; case AnimationType.Slide: var counter = 0; doubleAnimation.Completed += delegate { counter++; if (counter == 2) { finishAction(); } }; var trans = new ScaleTransform(); view.RenderTransform = trans; trans.BeginAnimation(ScaleTransform.ScaleXProperty, doubleAnimation); trans.BeginAnimation(ScaleTransform.ScaleYProperty, doubleAnimation); break; default: finishAction(); break; } }
private static void BeginZoomAnimation(double zoomValue) { // TODO Make zoom work when image rotated Point relative = Mouse.GetPosition(ConfigureWindows.GetMainWindow.MainImage); // Calculate new position double absoluteX = relative.X * scaleTransform.ScaleX + translateTransform.X; double absoluteY = relative.Y * scaleTransform.ScaleY + translateTransform.Y; // Reset to zero if value is one, which is reset double newTranslateValueX = zoomValue > 1 ? absoluteX - relative.X * zoomValue : 0; double newTranslateValueY = zoomValue > 1 ? absoluteY - relative.Y * zoomValue : 0; var duration = new Duration(TimeSpan.FromSeconds(.3)); var scaleAnim = new DoubleAnimation(zoomValue, duration) { // Set stop to make sure animation doesn't hold ownership of scaletransform FillBehavior = FillBehavior.Stop }; scaleAnim.Completed += delegate { // Hack it to keep the intended value scaleTransform.ScaleX = scaleTransform.ScaleY = zoomValue; // Make sure value stays correct ZoomValue = 1.0; }; var translateAnimX = new DoubleAnimation(translateTransform.X, newTranslateValueX, duration) { // Set stop to make sure animation doesn't hold ownership of translateTransform FillBehavior = FillBehavior.Stop }; translateAnimX.Completed += delegate { // Hack it to keep the intended value translateTransform.X = newTranslateValueX; }; var translateAnimY = new DoubleAnimation(translateTransform.Y, newTranslateValueY, duration) { // Set stop to make sure animation doesn't hold ownership of translateTransform FillBehavior = FillBehavior.Stop }; translateAnimY.Completed += delegate { // Hack it to keep the intended value translateTransform.Y = newTranslateValueY; }; // Start animations translateTransform.BeginAnimation(TranslateTransform.XProperty, translateAnimX); translateTransform.BeginAnimation(TranslateTransform.YProperty, translateAnimY); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnim); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnim); }
/* * 加载所有动画效果 * * @param currElement 当前控件 * * @param currDControl 当前控件数据 * * @param list 动画列表 */ public static void loadAllAnimation(FrameworkElement currElement, DControl currDControl, List <DControlAnimation> list, Cfg cfg) { double currOpacity = currDControl.opacity / 100.0; TransformGroup group = (TransformGroup)currElement.RenderTransform; // group.Children.Clear(); 多次加载动画需要归零 foreach (DControlAnimation animation in list) { if (animation.type == 1001) { //淡入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); currElement.Opacity = 0; IEasingFunction easingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0, currOpacity, easingFunction); currElement.BeginAnimation(UIElement.OpacityProperty, da); } else if (animation.type == 1002) { //从左移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1003) { //从右移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1004) { //从上移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1005) { //从下移入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1006) { //放大 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1007) { //缩小 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 1.5, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1101) { //从左旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1102) { //从右旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width * 1, 0); translateTransform.BeginAnimation(TranslateTransform.XProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1103) { //从上旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height * 1, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1104) { //从下旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height * 1, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1201) { //从左弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform12 = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0, easingFunction); translateTransform12.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1202) { //从右弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1203) { //从上弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1204) { //从下弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.YProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1205) { //中心弹入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0, easingFunction); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1301) { //从左斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 140, 180, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1302) { //从右斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 40, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width, 0, easingFunction); translateTransform.BeginAnimation(TranslateTransform.XProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1303) { //从上斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1304) { //从下斜入 currElement.RenderTransformOrigin = new Point(0.5, 0.5); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1); TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group); DoubleAnimation da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height, 0); translateTransform.BeginAnimation(TranslateTransform.YProperty, da2); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1401) { //从左绕入 currElement.RenderTransformOrigin = new Point(0, 0); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1402) { //从右绕入 currElement.RenderTransformOrigin = new Point(1, 1); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1403) { //从上绕入 currElement.RenderTransformOrigin = new Point(1, 0); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1404) { //从下绕入 currElement.RenderTransformOrigin = new Point(0, 1); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity); } else if (animation.type == 1501) { //翻开 currElement.RenderTransformOrigin = new Point(0.5, 0.5); SkewTransform skewTransform = TransformGroupUtil.GetSkewTransform(group); IEasingFunction easingFunction = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.1 }; DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 10, 0, easingFunction); skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da); ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); IEasingFunction easingFunction1 = new BackEase() { EasingMode = EasingMode.EaseInOut }; DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0.4, 1.0, easingFunction1); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1); IEasingFunction easingFunction2 = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2); } else if (animation.type == 1502) { //旋转 currElement.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group); DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da); IEasingFunction easingFunction2 = new CubicEase() { EasingMode = EasingMode.EaseIn }; DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2); } else if (animation.type == 1601) { //光晕 来回缩放 currElement.RenderTransformOrigin = new Point(0.5, 0.5); double halfSeconds = animation.durationSeconds / 2.0; DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); if (animation.playTimes <= 0) { da.RepeatBehavior = RepeatBehavior.Forever; } else { da.RepeatBehavior = new RepeatBehavior(animation.playTimes); } ScaleTransform scaleTransform = TransformGroupUtil.GetScaleTransform(group); var keyFrames = da.KeyFrames; IEasingFunction easingFunction = new CubicEase() { EasingMode = EasingMode.EaseIn }; keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(0))); keyFrames.Add(new LinearDoubleKeyFrame(0.78, TimeSpan.FromMilliseconds(halfSeconds))); keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(animation.durationSeconds))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da); } } }
public void AddItem(UIElement item) { Contract.Requires <ArgumentNullException>(item != null); Debug.Assert(VisualTreeHelper.GetParent(item) == null, "item", "item should not have a parent"); m_elements.Add(item); this.AddVisualChild(item); this.InvalidateMeasure(); item.RenderTransformOrigin = new Point(.5, .5); TransformGroup group = new TransformGroup(); group.Children.Add(new ScaleTransform(.6, .6)); ScaleTransform animatedScale = new ScaleTransform(); group.Children.Add(animatedScale); RotateTransform rotateTransform = new RotateTransform(); group.Children.Add(rotateTransform); group.Children.Add(new TranslateTransform()); item.RenderTransform = group; if (m_elements.Count >= c_maxCount) { int oldestCount = m_elements.Count - c_maxCount; for (int i = 0; i < oldestCount; i++) { UIElement oldest = m_elements[0]; m_fadingElements.Add(oldest); m_elements.RemoveAt(0); DoubleAnimation fadeOut = GetFadeOutAnimation(); fadeOut.Completed += delegate(object sender, EventArgs e) { m_fadingElements.Remove(oldest); this.RemoveVisualChild(oldest); }; oldest.BeginAnimation(UIElement.OpacityProperty, fadeOut); } } DoubleAnimation rotationAnimation = GetRandomRotateAnimation(); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotationAnimation); DoubleAnimation fadeIn = GetFadeInAnimation(); item.BeginAnimation(UIElement.OpacityProperty, fadeIn); DoubleAnimation shrink = GetShrinkAnimation(); animatedScale.BeginAnimation(ScaleTransform.ScaleXProperty, shrink); animatedScale.BeginAnimation(ScaleTransform.ScaleYProperty, shrink); }
public override void BeginHidden(UIElement element, Action complate = null) { var toSlide = element as FrameworkElement; var origin = this.RenderTransformOrigin; if (this.PointOriginType == PointOriginType.MousePosition) { // Do :按鼠标位置计算 var postion = Mouse.GetPosition(toSlide); double x = postion.X / toSlide.ActualWidth; double y = postion.Y / toSlide.ActualHeight; origin = new Point(x, y); } else if (this.PointOriginType == PointOriginType.RandomInner) { // Do :随机计算 Random random = new Random(); origin = new Point(random.NextDouble(), random.NextDouble()); } else if (this.PointOriginType == PointOriginType.Center) { // Do :中心点计算 origin = new Point(0.5, 0.5); } var horizontalProportion = toSlide.ActualWidth * origin.X; var verticalProportion = toSlide.ActualHeight * origin.Y; ImageBrush image = new ImageBrush(this.ImageSource); if (!IsSingle) { image.Viewport = this.Viewport; image.ViewportUnits = this.ViewportUnits; image.TileMode = this.TileMode; } ScaleTransform scaleTransform = new ScaleTransform(0, 0); scaleTransform.CenterX = horizontalProportion; scaleTransform.CenterY = verticalProportion; image.Transform = scaleTransform; toSlide.SetCurrentValue(UIElement.OpacityMaskProperty, image); DoubleAnimation animation = new DoubleAnimation(); animation.From = 8; animation.To = 0; animation.BeginTime = TimeSpan.FromMilliseconds(this.StartTime); animation.Duration = TimeSpan.FromMilliseconds(this.HideDuration); animation.Completed += (sender, args) => { element.SetCurrentValue(UIElement.OpacityMaskProperty, null); element.Visibility = Visibility.Collapsed; complate?.Invoke(); }; //animation.EasingFunction = new CircleEase() { EasingMode = EasingMode.EaseIn }; scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, animation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, animation); }
private static void OnLayoutScaleParamsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var scaleParams = e.NewValue as IScaleParams; var target = d as FrameworkElement; if (scaleParams == null || target == null) { return; } var scaleTransform = new ScaleTransform() { ScaleX = scaleParams.From.X, ScaleY = scaleParams.From.Y }; target.LayoutTransform = scaleTransform; RoutedEventHandler onLoaded = null; onLoaded = (_, __) => target.BeginInvoke(() => { target.Loaded -= onLoaded; if (Math.Abs(scaleParams.From.X - scaleParams.To.X) > 0.001) { var x = new DoubleAnimation { From = scaleParams.From.X, To = scaleParams.To.X, FillBehavior = scaleParams.FillBehavior, BeginTime = TimeSpan.FromMilliseconds(scaleParams.BeginTime), Duration = new Duration(TimeSpan.FromMilliseconds(scaleParams.Duration)), EasingFunction = scaleParams.Ease, AutoReverse = scaleParams.AutoReverse, }; scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, x); } if (Math.Abs(scaleParams.From.Y - scaleParams.To.Y) > 0.001) { var y = new DoubleAnimation { From = scaleParams.From.Y, To = scaleParams.To.Y, FillBehavior = scaleParams.FillBehavior, BeginTime = TimeSpan.FromMilliseconds(scaleParams.BeginTime), Duration = new Duration(TimeSpan.FromMilliseconds(scaleParams.Duration)), EasingFunction = scaleParams.Ease, AutoReverse = scaleParams.AutoReverse, }; scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, y); } }, DispatchPriority.DataBind); if (target.IsLoaded()) { onLoaded(null, null); } else { target.Loaded += onLoaded; } }
private void smartPhone_img_Click(object sender, RoutedEventArgs e) { //Console.WriteLine(smartPhoneCont.ObjectTouches.MoveCenter.X + " , " + smartPhoneCont.ObjectTouches.MoveCenter.Y); Console.WriteLine(smartPhoneCont.CenterFilter.Target.X + " , " + smartPhoneCont.CenterFilter.Target.Y); //smartPhoneCont.updatePosition(); PointF smartPos = new PointF(); double smartAngle = new double(); smartPos.X = smartPhoneCont.CenterFilter.Target.X; smartPos.Y = smartPhoneCont.CenterFilter.Target.Y; smartAngle = smartPhoneCont.RotateFilter.Target; _smartArea.setPosition(smartPos, smartAngle); smartAreaCont.SetPosition(smartPos.X, smartPos.Y, smartAngle, 1.0); if (_smartArea.Opacity == 0) { DoubleAnimation widthAnimation = new DoubleAnimation(); DoubleAnimation sizeAni = new DoubleAnimation(); sizeAni.From = 0; sizeAni.To = 1.0; sizeAni.Duration = TimeSpan.FromSeconds(0.2); widthAnimation.From = 0; widthAnimation.To = 1; widthAnimation.Duration = TimeSpan.FromSeconds(0.2); ScaleTransform oTransform = new ScaleTransform(); smartAreaCont.transforms = new TransformGroup(); smartAreaCont.transforms.Children.Add(oTransform); smartAreaCont.WorkingObject.RenderTransform = smartAreaCont.transforms; _smartArea.BeginAnimation(System.Windows.Controls.Image.OpacityProperty, widthAnimation); oTransform.BeginAnimation(ScaleTransform.ScaleXProperty, sizeAni); oTransform.BeginAnimation(ScaleTransform.ScaleYProperty, sizeAni); } else { DoubleAnimation widthAnimation = new DoubleAnimation(); DoubleAnimation sizeAni = new DoubleAnimation(); sizeAni.From = 1.0; sizeAni.To = 0; sizeAni.Duration = TimeSpan.FromSeconds(0.2); widthAnimation.From = 1.0; widthAnimation.To = 0; widthAnimation.Duration = TimeSpan.FromSeconds(0.2); ScaleTransform oTransform = new ScaleTransform(); smartAreaCont.transforms = new TransformGroup(); smartAreaCont.transforms.Children.Add(oTransform); smartAreaCont.WorkingObject.RenderTransform = smartAreaCont.transforms; _smartArea.BeginAnimation(System.Windows.Controls.Image.OpacityProperty, widthAnimation); oTransform.BeginAnimation(ScaleTransform.ScaleXProperty, sizeAni); oTransform.BeginAnimation(ScaleTransform.ScaleYProperty, sizeAni); } }
private void InitLine(double actualWidth, double actualHeight, bool usingAnima) { if (XAxis == null || YAxis == null || Points == null) { return; } ScaleTransform scale; if (usingAnima) { scale = new ScaleTransform() { ScaleY = 0 } } ; else { scale = new ScaleTransform() { ScaleY = 1 } }; polygon.RenderTransform = scale; polyline.RenderTransform = scale; var cvaHeight = actualHeight - _xHeight; var cvaWidth = actualWidth - _yWidth; var xHeight = cvaHeight / (YAxis.Count - 0.5); var yWidth = cvaWidth / (XAxis.Count - 0.5); var realHeight = cvaHeight - xHeight * 0.5; polyline.Points.Clear(); polygon.Points.Clear(); canvasPoints.Children.Clear(); var count = XAxis.Count > Points.Count ? Points.Count : XAxis.Count; for (int i = 0; i < count; i++) { var point = new Point(yWidth * i, (1 - Points[i].Value) * realHeight + 0.5 * xHeight); polyline.Points.Add(point); polygon.Points.Add(point); var ell = new Ellipse(); var toolTip = new PUChartToolTip() { Header = XAxis[i], Value = Points[i].ValueTip }; var cover = new Binding() { Source = this, Path = new PropertyPath("LineBrush"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(toolTip, PUChartToolTip.CoverBrushProperty, cover); ell.ToolTip = toolTip; var back = new Binding() { Source = this, Path = new PropertyPath("LineBrush"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(ell, Ellipse.FillProperty, back); var size = new Binding() { Source = this, Path = new PropertyPath("PointSize"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(ell, Ellipse.WidthProperty, size); BindingOperations.SetBinding(ell, Ellipse.HeightProperty, size); Canvas.SetLeft(ell, yWidth * i - PointSize / 2); if (usingAnima) { Canvas.SetTop(ell, cvaHeight - PointSize / 2); ell.BeginAnimation(Canvas.TopProperty, GetDoubleAnimation((1 - Points[i].Value) * realHeight + 0.5 * xHeight - PointSize / 2, 1)); } else { Canvas.SetTop(ell, (1 - Points[i].Value) * realHeight + 0.5 * xHeight - PointSize / 2); } canvasPoints.Children.Add(ell); } polygon.Points.Add(new Point(yWidth * (Points.Count - 1), cvaHeight)); polygon.Points.Add(new Point(0, cvaHeight)); if (usingAnima) { scale.BeginAnimation(ScaleTransform.ScaleYProperty, GetDoubleAnimation(1, 1)); } }
/// <summary> /// /// </summary> /// <param name="f"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="s_移動方式"></param> private void fun_旋轉動畫(FrameworkElement f, double d_角度_前, double d_角度_後, bool bool_水平鏡像_前, bool bool_水平鏡像_後, bool bool_垂直鏡像_前, bool bool_垂直鏡像_後) { if (f == null) { return; } if (M.s_img_type_顯示類型 == "WEB") { String int_角度 = Int32.Parse(d_角度_後 + "") + ""; String bool_水平 = (bool_水平鏡像_後) ? "-1" : "1"; String bool_垂直 = (bool_垂直鏡像_後) ? "-1" : "1"; M.img_web.Document.InvokeScript("fun_套用旋轉", new Object[] { d_角度_前 + "", d_角度_後 + "", (bool_水平鏡像_前) ? "-1" : "1", (bool_水平鏡像_後) ? "-1" : "1", (bool_垂直鏡像_前) ? "-1" : "1", (bool_垂直鏡像_後) ? "-1" : "1" }); return; } double d_運行時間 = 0.3d; //初始化角度 RotateTransform transform = new RotateTransform() { CenterX = 0.5, CenterY = 0.5, Angle = d_角度_前, }; //初始化縮放 ScaleTransform transform2 = new ScaleTransform() { CenterX = 0.5, CenterY = 0.5, ScaleX = (bool_水平鏡像_前) ? -1 : 1, ScaleY = (bool_垂直鏡像_前) ? -1 : 1, }; //放入變形群組 TransformGroup tf = new TransformGroup(); tf.Children.Add(transform); tf.Children.Add(transform2); //套用 f.LayoutTransform = tf; //設定動畫執行時間 DoubleAnimation animation = new DoubleAnimation() { From = d_角度_前, To = d_角度_後, Duration = TimeSpan.FromSeconds(d_運行時間), //RepeatBehavior = RepeatBehavior.Forever }; //設定動畫執行時間 DoubleAnimation animation2 = new DoubleAnimation() { From = (bool_水平鏡像_前) ? -1 : 1, To = (bool_水平鏡像_後) ? -1 : 1, Duration = TimeSpan.FromSeconds(d_運行時間), }; //設定動畫執行時間 DoubleAnimation animation3 = new DoubleAnimation() { From = (bool_垂直鏡像_前) ? -1 : 1, To = (bool_垂直鏡像_後) ? -1 : 1, Duration = TimeSpan.FromSeconds(d_運行時間), }; //執行動畫 transform.BeginAnimation(RotateTransform.AngleProperty, animation); if (bool_水平鏡像_前 != bool_水平鏡像_後) { transform2.BeginAnimation(ScaleTransform.ScaleXProperty, animation2); } if (bool_垂直鏡像_前 != bool_垂直鏡像_後) { transform2.BeginAnimation(ScaleTransform.ScaleYProperty, animation3); } }
//public override void BeginVisible(UIElement element, Action complate = null) //{ // this.Begin(element, 0, 1, this.VisibleDuration); //} void Begin(UIElement element, double from, double to, double duration, Action complate = null) { var toSlide = element as FrameworkElement; var origin = this.RenderTransformOrigin; if (this.PointOriginType == PointOriginType.MousePosition) { // Do :按鼠标位置计算 var postion = Mouse.GetPosition(toSlide); double x = postion.X / toSlide.ActualWidth; double y = postion.Y / toSlide.ActualHeight; origin = new Point(x, y); } if (this.PointOriginType == PointOriginType.MouseInnerOrCenter) { // Do :按鼠标位置计算 var postion = Mouse.GetPosition(toSlide); if (postion.X < 0 || postion.Y < 0) { origin = new Point(0.5, 0.5); } else { double x = postion.X / toSlide.ActualWidth; double y = postion.Y / toSlide.ActualHeight; origin = new Point(x, y); } } else if (this.PointOriginType == PointOriginType.RandomInner) { // Do :随机计算 Random random = new Random(); origin = new Point(random.NextDouble(), random.NextDouble()); } else if (this.PointOriginType == PointOriginType.Center) { // Do :中心点计算 origin = new Point(0.5, 0.5); } var horizontalProportion = toSlide.ActualWidth * Math.Max(1.0 - origin.X, 1.0 * origin.X); var verticalProportion = toSlide.ActualHeight * Math.Max(1.0 - origin.Y, 1.0 * origin.Y); var radius = Math.Sqrt(Math.Pow(horizontalProportion, 2) + Math.Pow(verticalProportion, 2)); var transformGroup = new TransformGroup(); var scaleTransform = new ScaleTransform(0, 0); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(toSlide.ActualWidth * origin.X, toSlide.ActualHeight * origin.Y); transformGroup.Children.Add(translateTransform); if (this.Geometry is EllipseGeometry ellipse) { ellipse.RadiusX = radius; ellipse.RadiusY = radius; } else if (this.Geometry is RectangleGeometry rectangle) { rectangle.Rect = new Rect(-horizontalProportion, -verticalProportion, 2 * horizontalProportion, 2 * verticalProportion); } this.Geometry.Transform = transformGroup; toSlide.SetCurrentValue(UIElement.ClipProperty, this.Geometry); var scaleAnimation = new DoubleAnimationUsingKeyFrames(); scaleAnimation.Completed += (sender, args) => { System.Diagnostics.Debug.WriteLine(this.Geometry.Bounds.Width); toSlide.SetCurrentValue(UIElement.ClipProperty, null); complate?.Invoke(); }; scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(from, TimeSpan.FromMilliseconds(this.StartTime))); scaleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(to, TimeSpan.FromMilliseconds(duration))); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation); }
/*This function displays a node on the screen. It is called only when a node is in the selected state to display its content. * Parameters * Int16[,] NodeProp- Node location * string textColor - Node's text color * double top - Top or y coordinate of the cluster location on screen * double left - Left or x coordinate of the cluster location on screen * Canvas PaintCanvas - The paintcanvas where it is to be displayed * int details - this parameter is unused and can be removed */ public void displayNode(Int16[,] NodeProp, string textColor, double top, double left, Canvas PaintCanvas, int details) { //stop and close any of the videos playing in previously selected node MainWindow.mp.Stop(); MainWindow.mp.Close(); //Create the ellipse for this node and assign values to its parameters Ellipse ellipse = new Ellipse(); ellipse.Height = NodeProp[0, 2]; ellipse.Width = NodeProp[0, 2]; ellipse.StrokeThickness = 0; BrushConverter bc = new BrushConverter(); Brush brush = (Brush)bc.ConvertFrom(color); ImageBrush im = new ImageBrush(); Label img = new Label(); /*This code finds the previously selected node on the paint canvas and removes any related nodes from it and hides its information content * because now another node is being selected for information */ foreach (FrameworkElement element in MainWindow.PaintCanvas.Children) { if (element is Grid) { Grid g = element as Grid; if (g != null && g.Children.Count > 6) { Ellipse e = g.Children[0] as Ellipse; Label l = new Label(); Label l1 = new Label(); l1 = g.Children[6] as Label; Label l2 = g.Children[5] as Label; l = g.Children[7] as Label; Label l3 = g.Children[4] as Label; BrushConverter BC = new BrushConverter(); Brush b = (Brush)BC.ConvertFrom(l.Content); TextBlock t = g.Children[1] as TextBlock; if (e.Fill != null && e.Height > 200) { e.Fill = b; t.Text = l3.Content.ToString(); t.Visibility = System.Windows.Visibility.Visible; e.Height = 240; e.Width = 240; } else if (e.Fill != null && e.Height > 100) { e.Visibility = System.Windows.Visibility.Hidden; t.Visibility = System.Windows.Visibility.Hidden; } } } } // store node's name in Textblock TextBlock txt = new TextBlock(); txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; txt.VerticalAlignment = System.Windows.VerticalAlignment.Center; txt.FontSize = 20; txt.Foreground = (Brush)bc.ConvertFrom(textColor); txt.FontWeight = System.Windows.FontWeights.Bold; txt.TextWrapping = System.Windows.TextWrapping.Wrap; txt.TextTrimming = TextTrimming.CharacterEllipsis; txt.Margin = new Thickness(15, 12, 15, 10); txt.Text = name; txt.Visibility = System.Windows.Visibility.Hidden; // Assign values to Labels for storing node's parent ID, //node's state, node's name, node's type,node's subject/discipline, and the node's fill color for the ellipse. Label lbl = new Label(); lbl.Content = nodeID; lbl.Visibility = System.Windows.Visibility.Hidden; Label lbl1 = new Label(); lbl1.Content = state; lbl1.Visibility = System.Windows.Visibility.Hidden; Label lbl2 = new Label(); lbl2.Content = name; lbl2.Visibility = System.Windows.Visibility.Hidden; Label lbl3 = new Label(); lbl3.Content = type; lbl3.Visibility = System.Windows.Visibility.Hidden; Label lbl4 = new Label(); lbl4.Content = subject; lbl4.Visibility = System.Windows.Visibility.Hidden; Label lbl5 = new Label(); lbl5.Content = color; lbl5.Visibility = System.Windows.Visibility.Hidden; //Add the children to the node grid. Each node grid consists of ellipse to show content, Textblock to store textual content, Labels for storing node's parent ID, //node's state, node's name, node's type,node's subject/discipline, and the node's fill color for the ellipse. Grid grid = new Grid(); grid.Height = NodeProp[0, 2]; grid.Width = NodeProp[0, 2]; grid.Children.Add(ellipse); grid.Children.Add(txt); grid.Children.Add(lbl); grid.Children.Add(lbl1); grid.Children.Add(lbl2); grid.Children.Add(lbl3); grid.Children.Add(lbl4); grid.Children.Add(lbl5); grid.MouseLeftButtonDown += new MouseButtonEventHandler(MainWindow.node_leftClick); //if this node has a video or image content, get its path and play/display it if (imgLink != "") { MainWindow.mp.Open(new Uri(@imgLink, UriKind.Relative)); VideoDrawing vDrawing = new VideoDrawing(); vDrawing.Rect = new Rect(0, 0, 100, 100); vDrawing.Player = MainWindow.mp; DrawingBrush db = new DrawingBrush(vDrawing); ellipse.Fill = db; MainWindow.mp.Play(); } //if this node does not have a video or image content, display its text information else { txt.Visibility = System.Windows.Visibility.Visible; txt.Text = content; txt.FontSize = 13; BrushConverter BC = new BrushConverter(); Brush b = (Brush)BC.ConvertFrom(color); ellipse.Fill = b; } PaintCanvas.Children.Add(grid); //this code animates the node and makes it get larger gradually when selected DoubleAnimation da = new DoubleAnimation(1.1, new Duration(TimeSpan.FromSeconds(2))); ScaleTransform sc = new ScaleTransform(); TransformGroup tg = new TransformGroup(); tg.Children.Add(sc); //add scaleTransform grid.RenderTransform = tg; grid.RenderTransformOrigin = new Point(0, 0); sc.BeginAnimation(ScaleTransform.ScaleXProperty, da); sc.BeginAnimation(ScaleTransform.ScaleYProperty, da); Canvas.SetLeft(grid, NodeProp[0, 1] + left); Canvas.SetTop(grid, NodeProp[0, 0] + top); // this loop deals with displaying all the related nodes of this particular node for (int i = 0; i < relNodes.Count; i++) { ellipse = new Ellipse(); ellipse.Height = NodeProp[i + 1, 2]; ellipse.Width = NodeProp[i + 1, 2]; ellipse.StrokeThickness = 1.5; bc = new BrushConverter(); brush = (Brush)bc.ConvertFrom(relNodes.ElementAt(i).color); ellipse.Fill = brush; txt = new TextBlock(); txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; txt.VerticalAlignment = System.Windows.VerticalAlignment.Center; txt.FontSize = 16; txt.Foreground = (Brush)bc.ConvertFrom(textColor); txt.FontWeight = System.Windows.FontWeights.Bold; txt.TextWrapping = System.Windows.TextWrapping.Wrap; txt.TextTrimming = TextTrimming.CharacterEllipsis; txt.Margin = new Thickness(15, 12, 15, 10); txt.Text = name; lbl = new Label(); lbl.Content = relNodes.ElementAt(i).nodeID; lbl.Visibility = System.Windows.Visibility.Hidden; lbl1 = new Label(); lbl1.Content = relNodes.ElementAt(i).state; lbl1.Visibility = System.Windows.Visibility.Hidden; lbl2 = new Label(); lbl2.Content = relNodes.ElementAt(i).name; lbl2.Visibility = System.Windows.Visibility.Hidden; lbl3 = new Label(); lbl3.Content = relNodes.ElementAt(i).type; lbl3.Visibility = System.Windows.Visibility.Hidden; lbl4 = new Label(); lbl4.Content = subject; lbl4.Visibility = System.Windows.Visibility.Hidden; lbl5 = new Label(); lbl5.Content = color; lbl5.Visibility = System.Windows.Visibility.Hidden; txt.Text = relNodes.ElementAt(i).name; grid = new Grid(); grid.Height = NodeProp[i + 1, 2]; grid.Width = NodeProp[i + 1, 2]; grid.Children.Add(ellipse); grid.Children.Add(txt); grid.Children.Add(lbl); grid.Children.Add(lbl1); grid.Children.Add(lbl2); grid.Children.Add(lbl3); grid.Children.Add(lbl4); grid.Children.Add(lbl5); PaintCanvas.Children.Add(grid); Canvas.SetLeft(grid, 0); Canvas.SetTop(grid, 0); // this code moves the related nodes from the top left corner of the screen onto the selected node DoubleAnimationUsingPath doublePathLR = new DoubleAnimationUsingPath(); DoubleAnimationUsingPath doublePathUD = new DoubleAnimationUsingPath(); TranslateTransform tr = new TranslateTransform(); grid.RenderTransform = tr; PathGeometry pg = new PathGeometry(); PathFigure pFigure = new PathFigure(); LineSegment lSegment = new LineSegment(); PathSegmentCollection collection = new PathSegmentCollection(); collection.Add(lSegment); lSegment.Point = new Point(NodeProp[i + 1, 1] + left, NodeProp[i + 1, 0] + top); //(200, 70); collection.Add(lSegment); pFigure.Segments = collection; PathFigureCollection conn = new PathFigureCollection(); conn.Add(pFigure); pg.Figures = conn; doublePathLR.PathGeometry = pg; doublePathLR.Duration = TimeSpan.FromSeconds(3); doublePathLR.Source = PathAnimationSource.X; doublePathUD.PathGeometry = pg; doublePathUD.Duration = TimeSpan.FromSeconds(3); doublePathUD.Source = PathAnimationSource.Y; //this actually makes the node move; it activates the animation tr.BeginAnimation(TranslateTransform.XProperty, doublePathLR); tr.BeginAnimation(TranslateTransform.YProperty, doublePathUD); } }