Exemplo n.º 1
0
        protected override void Init()
        {
            SetBaseView();

            RotateTransform translation = new RotateTransform();

            dau = new DoubleAnimationUsingKeyFrames();
            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation = new RotateTransform();
                Win.RegisterName(translation.GetHashCode().ToString(), translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    //当前Y值
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    }
                }
                else
                {
                    translation = new RotateTransform();
                    Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            double angle = translation.Angle;
            var    k2_0  = new EasingDoubleKeyFrame(RotateAngle, TimeSpan.FromMilliseconds(AniTime(0)));
            var    k2    = new EasingDoubleKeyFrame(angle, TimeSpan.FromMilliseconds(AniTime(1)));
            if (EasingFunction != null)
            {
                if (k2_0 != null)
                {
                    k2_0.EasingFunction = EasingFunction;
                }
                if (k2 != null)
                {
                    k2.EasingFunction = EasingFunction;
                }
            }

            Storyboard.SetTargetName(dau, Win.GetName(translation));

            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));

            Win.RegisterResource(Story);
            Story = (Storyboard)Story.CloneCurrentValue();
            dau.KeyFrames.Add(k2_0);
            dau.KeyFrames.Add(k2);
            Story.Children.Add(dau);

            if (OpacityNeed)
            {
                dauOpacty = new DoubleAnimationUsingKeyFrames();
                var k6   = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0)));
                var k6_1 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)));

                dauOpacty.KeyFrames.Add(k6);
                dauOpacty.KeyFrames.Add(k6_1);
                Storyboard.SetTarget(dauOpacty, Element);
                dauOpacty.FillBehavior = FillBehavior.Stop;
                Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
                Story.Children.Add(dauOpacty);
            }


            Story.Completed += Story_Completed;
        }
Exemplo n.º 2
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);
            Element.Visibility            = Visibility.Visible;

            RotateTransform translation     = new RotateTransform();
            string          translationName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    //当前Y值
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            double angle = translation.Angle;
            var    k2_0  = new EasingDoubleKeyFrame(RotateAngle, TimeSpan.FromMilliseconds(AniTime(0)));
            var    k2    = new EasingDoubleKeyFrame(angle, TimeSpan.FromMilliseconds(AniTime(1)));
            if (EasingFunction != null)
            {
                if (k2_0 != null)
                {
                    k2_0.EasingFunction = EasingFunction;
                }
                if (k2 != null)
                {
                    k2.EasingFunction = EasingFunction;
                }
            }

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));

            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2_0);
            dau.KeyFrames.Add(k2);
            story.Children.Add(dau);

            if (OpacityNeed)
            {
                DoubleAnimationUsingKeyFrames dauOpacty = new DoubleAnimationUsingKeyFrames();
                var k6   = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0)));
                var k6_1 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)));

                dauOpacty.KeyFrames.Add(k6);
                dauOpacty.KeyFrames.Add(k6_1);
                Storyboard.SetTarget(dauOpacty, Element);
                dauOpacty.FillBehavior = FillBehavior.Stop;
                Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
                story.Children.Add(dauOpacty);
            }



            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Element.Visibility = Visibility.Collapsed;

                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);

                    dau.KeyFrames.Clear();
                    dau   = null;
                    story = null;
                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Exemplo n.º 3
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.Visibility            = Visibility.Visible;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);

            RotateTransform translation      = new RotateTransform();
            ScaleTransform  translationScale = new ScaleTransform(1, 1);

            string translationName      = "";
            string translationScaleName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);

                translationScaleName = "ayTranslation" + translationScale.GetHashCode();
                Win.RegisterName(translationScaleName, translationScale);
                tg.Children.Add(translationScale);

                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                foreach (var item in tg.Children)
                {
                    translationScale = item as ScaleTransform;
                    if (translationScale != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    //当前Y值
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationScale != null)
                {
                    var tex = translationScale.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationScaleName = tex.ToString();
                    }
                    else
                    {
                        translationScaleName = "ayTranslation" + translationScale.GetHashCode();
                        Win.RegisterName(translationScaleName, translationScale);
                    }
                }
                else
                {
                    translationScale     = new ScaleTransform(1, 1);
                    translationScaleName = "ayTranslation" + translationScale.GetHashCode();
                    Win.RegisterName(translationScaleName, translationScale);
                    tg.Children.Add(translationScale);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            translation.CenterX = 0.5;
            translation.CenterY = 0;
            double angle = translation.Angle;
            var    k2    = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.1)));
            var    k2_1  = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var    k2_2  = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var    k2_3  = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.5)));
            var    k2_4  = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.7)));
            var    k2_5  = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.9)));
            var    k2_6  = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var    k2_7  = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var    k2_8  = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var    k2_9  = new EasingDoubleKeyFrame(angle, TimeSpan.FromMilliseconds(AnimateSpeed));

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));

            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k2_1);
            dau.KeyFrames.Add(k2_2);
            dau.KeyFrames.Add(k2_3);
            dau.KeyFrames.Add(k2_4);
            dau.KeyFrames.Add(k2_5);
            dau.KeyFrames.Add(k2_6);
            dau.KeyFrames.Add(k2_7);
            dau.KeyFrames.Add(k2_8);
            dau.KeyFrames.Add(k2_9);

            story.Children.Add(dau);


            DoubleAnimationUsingKeyFrames dauScaleX = new DoubleAnimationUsingKeyFrames();
            DoubleAnimationUsingKeyFrames dauScaleY = new DoubleAnimationUsingKeyFrames();
            double scaleX = translationScale.ScaleX;
            double scaleY = translationScale.ScaleY;
            double s1     = scaleX + tadaScale;
            double s2     = scaleX - tadaScale;

            double s3 = scaleY + tadaScale;
            double s4 = scaleY - tadaScale;

            var k3   = new EasingDoubleKeyFrame(s2, TimeSpan.FromMilliseconds(AniTime(0.1)));
            var k3_1 = new EasingDoubleKeyFrame(s2, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var k3_2 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var k3_3 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.5)));
            var k3_4 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.7)));
            var k3_5 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.9)));
            var k3_6 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k3_7 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k3_8 = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k3_9 = new EasingDoubleKeyFrame(scaleX, TimeSpan.FromMilliseconds(AnimateSpeed));


            var k4   = new EasingDoubleKeyFrame(s4, TimeSpan.FromMilliseconds(AniTime(0.1)));
            var k4_1 = new EasingDoubleKeyFrame(s4, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var k4_2 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var k4_3 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.5)));
            var k4_4 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.7)));
            var k4_5 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.9)));
            var k4_6 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k4_7 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k4_8 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k4_9 = new EasingDoubleKeyFrame(scaleY, TimeSpan.FromMilliseconds(AnimateSpeed));


            Storyboard.SetTargetName(dauScaleX, translationScaleName);
            Storyboard.SetTargetProperty(dauScaleX, new PropertyPath(ScaleTransform.ScaleXProperty));
            Storyboard.SetTargetName(dauScaleY, translationScaleName);
            Storyboard.SetTargetProperty(dauScaleY, new PropertyPath(ScaleTransform.ScaleYProperty));

            dauScaleX.KeyFrames.Add(k3);
            dauScaleX.KeyFrames.Add(k3_1);
            dauScaleX.KeyFrames.Add(k3_2);
            dauScaleX.KeyFrames.Add(k3_3);
            dauScaleX.KeyFrames.Add(k3_4);
            dauScaleX.KeyFrames.Add(k3_5);
            dauScaleX.KeyFrames.Add(k3_6);
            dauScaleX.KeyFrames.Add(k3_7);
            dauScaleX.KeyFrames.Add(k3_8);
            dauScaleX.KeyFrames.Add(k3_9);

            story.Children.Add(dauScaleX);


            dauScaleY.KeyFrames.Add(k4);
            dauScaleY.KeyFrames.Add(k4_1);
            dauScaleY.KeyFrames.Add(k4_2);
            dauScaleY.KeyFrames.Add(k4_3);
            dauScaleY.KeyFrames.Add(k4_4);
            dauScaleY.KeyFrames.Add(k4_5);
            dauScaleY.KeyFrames.Add(k4_6);
            dauScaleY.KeyFrames.Add(k4_7);
            dauScaleY.KeyFrames.Add(k4_8);
            dauScaleY.KeyFrames.Add(k4_9);

            story.Children.Add(dauScaleY);


            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);
                    Win.UnregisterName(translationScaleName);
                    dau.KeyFrames.Clear();
                    dauScaleX.KeyFrames.Clear();
                    dauScaleY.KeyFrames.Clear();
                    dauScaleX = null;
                    dauScaleY = null;
                    dau       = null;
                    story     = null;

                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Exemplo n.º 4
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0, 0);
            Element.Visibility            = Visibility.Visible;

            RotateTransform    translation          = new RotateTransform();
            TranslateTransform translationTranslate = new TranslateTransform(0, 0);

            string translationName          = "";
            string translationTranslateName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);

                translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                Win.RegisterName(translationTranslateName, translationTranslate);
                tg.Children.Add(translationTranslate);

                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                foreach (var item in tg.Children)
                {
                    translationTranslate = item as TranslateTransform;
                    if (translationTranslate != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationTranslate != null)
                {
                    var tex = translationTranslate.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationTranslateName = tex.ToString();
                    }
                    else
                    {
                        translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                        Win.RegisterName(translationTranslateName, translationTranslate);
                    }
                }
                else
                {
                    translationTranslate     = new TranslateTransform(0, 0);
                    translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                    Win.RegisterName(translationTranslateName, translationTranslate);
                    tg.Children.Add(translationTranslate);
                    Element.RenderTransform = tg;
                }
            }
            #endregion


            var k2   = new EasingDoubleKeyFrame(80, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var k2_2 = new EasingDoubleKeyFrame(40, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k2_1 = new EasingDoubleKeyFrame(75, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k2_3 = new EasingDoubleKeyFrame(60, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k2_4 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)), new CircleEase()
            {
                EasingMode = EasingMode.EaseOut
            });

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));
            dau.FillBehavior = FillBehavior.Stop;
            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k2_1);
            dau.KeyFrames.Add(k2_2);
            dau.KeyFrames.Add(k2_3);
            dau.KeyFrames.Add(k2_4);


            story.Children.Add(dau);



            DoubleAnimationUsingKeyFrames dauTranslateY = new DoubleAnimationUsingKeyFrames();
            var k3   = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k3_1 = new EasingDoubleKeyFrame(700, TimeSpan.FromMilliseconds(AniTime(1)));

            Storyboard.SetTargetName(dauTranslateY, translationTranslateName);
            Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.YProperty));

            dauTranslateY.KeyFrames.Add(k3);
            dauTranslateY.KeyFrames.Add(k3_1);
            story.Children.Add(dauTranslateY);
            dauTranslateY.FillBehavior = FillBehavior.Stop;


            DoubleAnimationUsingKeyFrames dauOpacty = new DoubleAnimationUsingKeyFrames();
            var k4   = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k4_0 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)));

            dauOpacty.KeyFrames.Add(k4);
            dauOpacty.KeyFrames.Add(k4_0);

            Storyboard.SetTarget(dauOpacty, Element);
            dauOpacty.FillBehavior = FillBehavior.Stop;
            Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
            story.Children.Add(dauOpacty);


            //PointAnimationUsingKeyFrames porender = new PointAnimationUsingKeyFrames();
            //var k5 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(0));
            //var k5_0 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(AniTime(0.8)));
            ////var k5_1 = new EasingPointKeyFrame(new Point(0.4, 0.9), TimeSpan.FromMilliseconds(AniTime(0.8001)));
            //porender.KeyFrames.Add(k5);
            //porender.KeyFrames.Add(k5_0);
            ////porender.KeyFrames.Add(k5_1);

            //Storyboard.SetTarget(porender, Element);
            //dauOpacty.FillBehavior = FillBehavior.Stop;
            //Storyboard.SetTargetProperty(porender, new PropertyPath(UIElement.RenderTransformOriginProperty));
            //story.Children.Add(porender);

            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Element.Visibility = Visibility.Collapsed;

                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);
                    Win.UnregisterName(translationTranslateName);

                    dau.KeyFrames.Clear();
                    dauTranslateY.KeyFrames.Clear();

                    dauTranslateY = null;
                    dau           = null;
                    story         = null;

                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Exemplo n.º 5
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.Visibility            = Visibility.Visible;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);

            RotateTransform    translation          = new RotateTransform();
            TranslateTransform translationTranslate = new TranslateTransform(0, 0);

            string translationName          = "";
            string translationTranslateName = "";

            Storyboard story = new Storyboard();
            DoubleAnimationUsingKeyFrames dau = new DoubleAnimationUsingKeyFrames();

            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);

                translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                Win.RegisterName(translationTranslateName, translationTranslate);
                tg.Children.Add(translationTranslate);

                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                foreach (var item in tg.Children)
                {
                    translationTranslate = item as TranslateTransform;
                    if (translationTranslate != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationTranslate != null)
                {
                    var tex = translationTranslate.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationTranslateName = tex.ToString();
                    }
                    else
                    {
                        translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                        Win.RegisterName(translationTranslateName, translationTranslate);
                    }
                }
                else
                {
                    translationTranslate     = new TranslateTransform(0, 0);
                    translationTranslateName = "ayTranslation" + translationTranslate.GetHashCode();
                    Win.RegisterName(translationTranslateName, translationTranslate);
                    tg.Children.Add(translationTranslate);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            translation.CenterX = 0.5;
            translation.CenterY = 1;

            double angle = translation.Angle;
            var    k2    = new EasingDoubleKeyFrame(angle - 5, TimeSpan.FromMilliseconds(AniTime(0.15)));
            var    k2_1  = new EasingDoubleKeyFrame(angle + 3, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var    k2_2  = new EasingDoubleKeyFrame(angle - 3, TimeSpan.FromMilliseconds(AniTime(0.45)));
            var    k2_3  = new EasingDoubleKeyFrame(angle + 2, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var    k2_4  = new EasingDoubleKeyFrame(angle - 1, TimeSpan.FromMilliseconds(AniTime(0.75)));
            var    k2_9  = new EasingDoubleKeyFrame(angle, TimeSpan.FromMilliseconds(AnimateSpeed));

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));

            var storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k2_1);
            dau.KeyFrames.Add(k2_2);
            dau.KeyFrames.Add(k2_3);
            dau.KeyFrames.Add(k2_4);
            dau.KeyFrames.Add(k2_9);

            story.Children.Add(dau);



            DoubleAnimationUsingKeyFrames dauTranslateX = new DoubleAnimationUsingKeyFrames();
            double lateX        = translationTranslate.X;
            double elementWidth = Element.RenderSize.Width;
            double s1           = lateX + (-0.25 * elementWidth);
            double s2           = lateX + (0.2 * elementWidth);

            double s3 = lateX + (-0.15 * elementWidth);
            double s4 = lateX + (0.1 * elementWidth);
            double s5 = lateX + (-0.05 * elementWidth);

            var k3   = new EasingDoubleKeyFrame(s1, TimeSpan.FromMilliseconds(AniTime(0.15)));
            var k3_1 = new EasingDoubleKeyFrame(s2, TimeSpan.FromMilliseconds(AniTime(0.3)));
            var k3_2 = new EasingDoubleKeyFrame(s3, TimeSpan.FromMilliseconds(AniTime(0.45)));
            var k3_3 = new EasingDoubleKeyFrame(s4, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k3_4 = new EasingDoubleKeyFrame(s5, TimeSpan.FromMilliseconds(AniTime(0.75)));
            var k3_9 = new EasingDoubleKeyFrame(lateX, TimeSpan.FromMilliseconds(AnimateSpeed));

            Storyboard.SetTargetName(dauTranslateX, translationTranslateName);
            Storyboard.SetTargetProperty(dauTranslateX, new PropertyPath(TranslateTransform.XProperty));

            dauTranslateX.KeyFrames.Add(k3);
            dauTranslateX.KeyFrames.Add(k3_1);
            dauTranslateX.KeyFrames.Add(k3_2);
            dauTranslateX.KeyFrames.Add(k3_3);
            dauTranslateX.KeyFrames.Add(k3_4);
            dauTranslateX.KeyFrames.Add(k3_9);

            story.Children.Add(dauTranslateX);



            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);
                    Win.UnregisterName(translationTranslateName);

                    dau.KeyFrames.Clear();
                    dauTranslateX.KeyFrames.Clear();

                    dauTranslateX = null;
                    dau           = null;
                    story         = null;

                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Exemplo n.º 6
0
        public override MyAnimateBase Animate()
        {
            IsAnimateCompleted            = false;
            Element.RenderTransformOrigin = new Point(0.5, 0.5);
            Element.Visibility            = Visibility.Visible;
            RotateTransform translation = new RotateTransform();



            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation     = new RotateTransform();
                translationName = "ayTranslation" + translation.GetHashCode();
                Win.RegisterName(translationName, translation);
                tg.Children.Add(translation);
                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                if (translation != null)
                {
                    //当前Y值
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                        translationName = tex.ToString();
                    }
                    else
                    {
                        translationName = "ayTranslation" + translation.GetHashCode();
                        Win.RegisterName(translationName, translation);
                    }
                }
                else
                {
                    translation     = new RotateTransform();
                    translationName = "ayTranslation" + translation.GetHashCode();
                    Win.RegisterName(translationName, translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }
            }
            #endregion
            double angle = translation.Angle;
            //如果旋转角度和最终的是一致的就不执行下面代码
            if (RotateAngleTo.HasValue && RotateAngleTo == angle)
            {
                return(this);
            }
            EasingDoubleKeyFrame k2 = null;
            if (RotateAngleAdd.HasValue)
            {
                k2 = new EasingDoubleKeyFrame(RotateAngleAdd.Value + angle, TimeSpan.FromMilliseconds(AniTime(1)));
            }
            else if (RotateAngleTo.HasValue)
            {
                k2 = new EasingDoubleKeyFrame(RotateAngleTo.Value, TimeSpan.FromMilliseconds(AniTime(1)));
            }

            if (!RotateAngleAdd.HasValue && !RotateAngleTo.HasValue)
            {
                k2 = new EasingDoubleKeyFrame(RotateAngleAdd.Value + 360, TimeSpan.FromMilliseconds(AniTime(1)));
            }
            if (EasingFunction != null)
            {
                k2.EasingFunction = EasingFunction;
            }

            Storyboard.SetTargetName(dau, translationName);
            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));

            if (AniRepeatBehavior.HasValue)
            {
                story.RepeatBehavior = AniRepeatBehavior.Value;
            }

            if (AniAutoReverse.HasValue)
            {
                story.AutoReverse = AniAutoReverse.Value;
            }

            storyboardName = "aystory" + story.GetHashCode();
            Win.Resources.Add(storyboardName, story);

            dau.KeyFrames.Add(k2);

            story.Children.Add(dau);



            story.Completed +=
                (sndr, evtArgs) =>
            {
                try
                {
                    Win.Resources.Remove(storyboardName);
                    Win.UnregisterName(translationName);

                    dau.KeyFrames.Clear();
                    dau = null;
                    story.Children.Clear();
                    story = null;
                    base.CallClientCompleted();
                }
                catch
                {
                }
            };
            story.Begin(); return(this);
        }
Exemplo n.º 7
0
        protected override void Init()
        {
            SetBaseView();
            RotateTransform    translation          = new RotateTransform();
            TranslateTransform translationTranslate = new TranslateTransform(0, 0);

            dau = new DoubleAnimationUsingKeyFrames();
            #region 基本工作,确定类型和name
            //是否存在TranslateTransform
            //动画要的类型是否存在
            //动画要的类型的name是否存在,不存在就注册,结束后取消注册,删除动画
            var ex = Element.RenderTransform;
            if (ex == null || (ex as System.Windows.Media.MatrixTransform) != null)
            {
                var tg = new TransformGroup();
                translation = new RotateTransform();
                Win.RegisterName(translation.GetHashCode().ToString(), translation);
                tg.Children.Add(translation);

                Win.RegisterName(translationTranslate.GetHashCode().ToString(), translationTranslate);
                tg.Children.Add(translationTranslate);

                Element.RenderTransform = tg;
            }
            else
            {
                var tg = ex as TransformGroup;
                foreach (var item in tg.Children)
                {
                    translation = item as RotateTransform;
                    if (translation != null)
                    {
                        break;
                    }
                }
                foreach (var item in tg.Children)
                {
                    translationTranslate = item as TranslateTransform;
                    if (translationTranslate != null)
                    {
                        break;
                    }
                }

                if (translation != null)
                {
                    var tex = translation.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    }
                }
                else
                {
                    translation = new RotateTransform();
                    Win.RegisterName(translation.GetHashCode().ToString(), translation);
                    tg.Children.Add(translation);
                    Element.RenderTransform = tg;
                }

                if (translationTranslate != null)
                {
                    var tex = translationTranslate.GetValue(FrameworkElement.NameProperty);
                    if (tex != null && tex.ToString() != "")
                    {
                    }
                    else
                    {
                        Win.RegisterName(translationTranslate);
                    }
                }
                else
                {
                    translationTranslate = new TranslateTransform(0, 0);
                    Win.RegisterName(translationTranslate);
                    tg.Children.Add(translationTranslate);
                    Element.RenderTransform = tg;
                }
            }
            #endregion

            Story = (Storyboard)Story.CloneCurrentValue();
            var k2   = new EasingDoubleKeyFrame(80, TimeSpan.FromMilliseconds(AniTime(0.2)));
            var k2_2 = new EasingDoubleKeyFrame(40, TimeSpan.FromMilliseconds(AniTime(0.4)));
            var k2_1 = new EasingDoubleKeyFrame(75, TimeSpan.FromMilliseconds(AniTime(0.6)));
            var k2_3 = new EasingDoubleKeyFrame(60, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k2_4 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)), new CircleEase()
            {
                EasingMode = EasingMode.EaseOut
            });

            Storyboard.SetTargetName(dau, Win.GetName(translation));

            Storyboard.SetTargetProperty(dau, new PropertyPath(RotateTransform.AngleProperty));
            dau.FillBehavior = FillBehavior.Stop;
            Win.RegisterResource(Story);
            dau.KeyFrames.Add(k2);
            dau.KeyFrames.Add(k2_1);
            dau.KeyFrames.Add(k2_2);
            dau.KeyFrames.Add(k2_3);
            dau.KeyFrames.Add(k2_4);


            Story.Children.Add(dau);



            dauTranslateY = new DoubleAnimationUsingKeyFrames();
            var k3   = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k3_1 = new EasingDoubleKeyFrame(700, TimeSpan.FromMilliseconds(AniTime(1)));

            Storyboard.SetTargetName(dauTranslateY, Win.GetName(translationTranslate));
            Storyboard.SetTargetProperty(dauTranslateY, new PropertyPath(TranslateTransform.YProperty));

            dauTranslateY.KeyFrames.Add(k3);
            dauTranslateY.KeyFrames.Add(k3_1);
            Story.Children.Add(dauTranslateY);
            dauTranslateY.FillBehavior = FillBehavior.Stop;


            dauOpacty = new DoubleAnimationUsingKeyFrames();
            var k4   = new EasingDoubleKeyFrame(1, TimeSpan.FromMilliseconds(AniTime(0.8)));
            var k4_0 = new EasingDoubleKeyFrame(0, TimeSpan.FromMilliseconds(AniTime(1)));

            dauOpacty.KeyFrames.Add(k4);
            dauOpacty.KeyFrames.Add(k4_0);

            Storyboard.SetTarget(dauOpacty, Element);
            dauOpacty.FillBehavior = FillBehavior.Stop;
            Storyboard.SetTargetProperty(dauOpacty, new PropertyPath(UIElement.OpacityProperty));
            Story.Children.Add(dauOpacty);


            //PointAnimationUsingKeyFrames porender = new PointAnimationUsingKeyFrames();
            //var k5 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(0));
            //var k5_0 = new EasingPointKeyFrame(new Point(0, 0), TimeSpan.FromMilliseconds(AniTime(0.8)));
            ////var k5_1 = new EasingPointKeyFrame(new Point(0.4, 0.9), TimeSpan.FromMilliseconds(AniTime(0.8001)));
            //porender.KeyFrames.Add(k5);
            //porender.KeyFrames.Add(k5_0);
            ////porender.KeyFrames.Add(k5_1);

            //Storyboard.SetTarget(porender, Element);
            //dauOpacty.FillBehavior = FillBehavior.Stop;
            //Storyboard.SetTargetProperty(porender, new PropertyPath(UIElement.RenderTransformOriginProperty));
            //story.Children.Add(porender);


            Story.Completed += Story_Completed;
        }