Esempio n. 1
0
 public void BeginAnimation(
     DependencyProperty dp, 
     AnimationTimeline animation, 
     HandoffBehavior handoffBehavior)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
        private void UpdateThumb()
        {
            if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null)
            {
                double destination = IsChecked.GetValueOrDefault() ? ActualWidth - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.ActualWidth) : 0;

                _thumbAnimation                = new DoubleAnimation();
                _thumbAnimation.To             = destination;
                _thumbAnimation.Duration       = TimeSpan.FromMilliseconds(500);
                _thumbAnimation.EasingFunction = new ExponentialEase()
                {
                    Exponent = 9
                };
                _thumbAnimation.FillBehavior = FillBehavior.Stop;

                AnimationTimeline currentAnimation = _thumbAnimation;
                _thumbAnimation.Completed += (sender, e) =>
                {
                    if (_thumbAnimation != null && currentAnimation == _thumbAnimation)
                    {
                        _ThumbTranslate.X = destination;
                        _thumbAnimation   = null;
                    }
                };
                _ThumbTranslate.BeginAnimation(TranslateTransform.XProperty, _thumbAnimation);
            }
        }
Esempio n. 3
0
        void da_Completed(object sender, EventArgs e)
        {
            AnimationTimeline timeline = (sender as AnimationClock).Timeline;
            /* !!! 通过附加属性把UI对象取回 !!! */
            object uiElement = Storyboard.GetTarget(timeline);

            TextBlock  t  = uiElement as TextBlock;
            StackPanel sp = t.Parent as StackPanel;

            sp.Children.Remove(t);


            if (sp.Children.Count <= 0)
            {
                if (win != null)
                {
                    win.Close();
                }
                win = null;
                return;
            }

            win.Left = SystemParameters.WorkArea.Width - win.Width;
            win.Top  = SystemParameters.WorkArea.Height - win.Height - 20;
        }
Esempio n. 4
0
        /// <summary>
        /// Starts an animation for a DependencyProperty. The animation will
        /// begin when the next frame is rendered.
        /// </summary>
        /// <param name="dp">
        /// The DependencyProperty to animate.
        /// </param>
        /// <param name="animation">
        /// <para>The AnimationTimeline to used to animate the property.</para>
        /// <para>If the AnimationTimeline's BeginTime is null, any current animations
        /// will be removed and the current value of the property will be held.</para>
        /// <para>If this value is null, all animations will be removed from the property
        /// and the property value will revert back to its base value.</para>
        /// </param>
        /// <param name="handoffBehavior">
        /// Specifies how the new animation should interact with any current
        /// animations already affecting the property value.
        /// </param>
        public void BeginAnimation(DependencyProperty dp, AnimationTimeline animation, HandoffBehavior handoffBehavior)
        {
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            if (!AnimationStorage.IsPropertyAnimatable(this, dp))
            {
        #pragma warning disable 56506 // Suppress presharp warning: Parameter 'dp' to this public method must be validated:  A null-dereference can occur here.
                throw new ArgumentException(SR.Get(SRID.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), "dp");
        #pragma warning restore 56506
            }

            if (animation != null &&
                !AnimationStorage.IsAnimationValid(dp, animation))
            {
                throw new ArgumentException(SR.Get(SRID.Animation_AnimationTimelineTypeMismatch, animation.GetType(), dp.Name, dp.PropertyType), "animation");
            }

            if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))
            {
                throw new ArgumentException(SR.Get(SRID.Animation_UnrecognizedHandoffBehavior));
            }

            if (IsSealed)
            {
                throw new InvalidOperationException(SR.Get(SRID.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));
            }

            AnimationStorage.BeginAnimation(this, dp, animation, handoffBehavior);
        }
        public static void AnimatePropertyTo <T, R, AT>(this T element, Expression <Func <T, R> > p, R finalValue, double duration, bool autoReverse)
            where T : IAnimatable
            where AT : AnimationTimeline
        {
            AnimationTimeline animation = (AnimationTimeline)Activator.CreateInstance(typeof(AT));

            if (animation == null)
            {
                return;
            }

            var prop         = (p.Body as MemberExpression).Member.Name;
            var currentValue = p.Compile()(element);

            DependencyPropertyDescriptor dFrom = DependencyPropertyDescriptor.FromName("From", animation.GetType(), animation.GetType());

            animation.SetValue(dFrom.DependencyProperty, currentValue);

            DependencyPropertyDescriptor dTo = DependencyPropertyDescriptor.FromName("To", animation.GetType(), animation.GetType());

            animation.SetValue(dTo.DependencyProperty, finalValue);

            animation.Duration    = new Duration(TimeSpan.FromSeconds(duration));
            animation.AutoReverse = autoReverse;

            DependencyPropertyDescriptor d = DependencyPropertyDescriptor.FromName(prop, typeof(T), typeof(T));

            element.BeginAnimation(d.DependencyProperty, null);
            element.BeginAnimation(d.DependencyProperty, animation);
        }
        public void AddAnimationTrack(string layer)
        {
            var track = CreateInstance <AnimationTrack>();

            USUndoManager.RegisterCreatedObjectUndo(track, "Add New Track");

            track.Layer = MecanimAnimationUtility.LayerNameToIndex(AnimationTimeline.AffectedObject.gameObject, layer);

            USUndoManager.RegisterCompleteObjectUndo(AnimationTimeline, "Add New Track");
            AnimationTimeline.AddTrack(track);

            var hierarchyItem = CreateInstance(typeof(USAnimationTimelineTrackHierarchyItem)) as USAnimationTimelineTrackHierarchyItem;

            USUndoManager.RegisterCreatedObjectUndo(hierarchyItem, "Add New Track");
            hierarchyItem.AnimationTrack             = track;
            hierarchyItem.AnimationTimelineHierarchy = this;
            hierarchyItem.AnimationTimeline          = AnimationTimeline;
            hierarchyItem.Initialize(AnimationTimeline);

            USUndoManager.RegisterCompleteObjectUndo(USHierarchy, "Add New Track");
            USHierarchy.RootItems.Add(hierarchyItem as IUSHierarchyItem);

            if (AnimationTimeline.AnimationTracks.Count == 1)
            {
                IsExpanded = true;
            }
        }
 /// <summary>
 /// Sets the animation out for the message.
 /// </summary>
 /// <param name="animation"></param>
 public void SetAnimationOut(AnimationTimeline animation)
 {
     if (this.Message is INotificationAnimation notificationAnimation)
     {
         notificationAnimation.AnimationOut = animation;
     }
 }
        private static AnimationClock Animate(
            DependencyObject animatable,
            DependencyProperty prop,
            AnimationTimeline anim,
            int duration,
            double?accel,
            double?decel,
            EventHandler func)
        {
            anim.AccelerationRatio = accel.GetValueOrDefault(0.0);
            anim.DecelerationRatio = decel.GetValueOrDefault(0.0);
            anim.Duration          = (Duration)TimeSpan.FromMilliseconds((double)duration);
            anim.Freeze();
            AnimationClock animClock = anim.CreateClock();

            animClock.Completed += new EventHandler(animClock_Completed);
            if (func != null)
            {
                animClock.Completed += func;
            }
            animClock.Controller.Begin();
            Animator.ClearAnimation(animatable, prop);
            ((IAnimatable)animatable).ApplyAnimationClock(prop, animClock);
            return(animClock);

            void animClock_Completed(object sender, EventArgs e)
            {
                Animator.ClearAnimation(animatable, prop);
                // ISSUE: method pointer
                animClock.Completed -= new EventHandler((object)this, __methodptr(\u003CAnimate\u003Eg__animClock_Completed\u007C0));
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Sets the animation in for the message.
 /// </summary>
 /// <param name="animation"></param>
 public void SetAnimationIn(AnimationTimeline animation)
 {
     if (this.Message is INotificationAnimation)
     {
         ((INotificationAnimation)this.Message).AnimationIn = animation;
     }
 }
Esempio n. 10
0
        private void Animation_Completed(object sender, EventArgs e)
        {
            AnimationTimeline timeline = (sender as AnimationClock).Timeline;
            Grid uIElement             = Storyboard.GetTarget(timeline) as Grid;

            positionDic[uIElement.Name].CanvasLeft = Canvas.GetLeft(uIElement);
            positionDic[uIElement.Name].CanvasTop  = Canvas.GetTop(uIElement);
            uIElement.BeginAnimation(Canvas.LeftProperty, null);
            Canvas.SetLeft(uIElement, positionDic[uIElement.Name].CanvasLeft);

            //Border b=null;
            //foreach (var item in borderMap)
            //{
            //    var border = item.Key;
            //    if (Canvas.GetLeft(uIElement) == Canvas.GetLeft(border) &&
            //        Canvas.GetTop(uIElement) == Canvas.GetTop(border))
            //    {
            //        b = border;
            //    }
            //}
            //if (b != null)
            //{
            //    borderMap[b] = uIElement;
            //}
        }
Esempio n. 11
0
        private void RemoveAnimationTrack()
        {
            USUndoManager.RegisterCompleteObjectUndo(AnimationTimeline, "Remove Track");
            AnimationTimeline.RemoveTrack(AnimationTrack);

            AnimationTimelineHierarchy.RemoveAnimationTrack(AnimationTrack);
        }
Esempio n. 12
0
 /// <summary>
 ///     Enqueues the specified element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="animation">The animation.</param>
 public void Enqueue(FrameworkElement element, AnimationTimeline animation)
 {
     if (element != null && animation != null)
     {
         this.animationQueue.Enqueue(new AnimationItem(element, animation));
     }
 }
Esempio n. 13
0
 private void AddAnimation(double beginTime, UIElement element, AnimationTimeline anim, DependencyProperty property)
 {
     anim.BeginTime = TimeSpan.FromSeconds(beginTime);
     Storyboard.SetTarget(anim, element);
     Storyboard.SetTargetProperty(anim, new PropertyPath(property));
     storyboard.Children.Add(anim);
 }
Esempio n. 14
0
 private void CreateFadeInAnimation()
 {
     fadeInAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(2)))
     {
         DecelerationRatio = 0.7,
         FillBehavior      = FillBehavior.HoldEnd
     };
 }
Esempio n. 15
0
 private void CreateEndlessFadeAnimation()
 {
     endlessFadeAnimation = new DoubleAnimation(0, 0.4, new Duration(TimeSpan.FromSeconds(0.2)))
     {
         AutoReverse = true
     };
     endlessFadeAnimation.Completed += FadeInAnimation_Completed;
 }
Esempio n. 16
0
 private void CreateHideSearchAnimation()
 {
     searchHideAnimation = new DoubleAnimation(1, 0.0, new Duration(TimeSpan.FromSeconds(0.5)))
     {
         FillBehavior = FillBehavior.HoldEnd
     };
     searchHideAnimation.Completed += SearchHideAnimation_Completed;
 }
Esempio n. 17
0
        /// <inheritdoc/>
        public override void AddToStoryboard(Storyboard storyBoard, AnimationTimeline timeline = null)
        {
            var animation = timeline ?? Get();

            Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));

            storyBoard.Children.Add(animation);
        }
Esempio n. 18
0
        public static Storyboard CreateStoryboard(AnimationTimeline timeline)
        {
            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(timeline);

            return(storyboard);
        }
Esempio n. 19
0
        /// <summary>
        /// Sets the animation out for the message.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="animation">The animation time line.</param>
        /// <returns>Returns the notification message builder.</returns>
        public static NotificationMessageBuilder AnimationOut(
            this NotificationMessageBuilder builder,
            AnimationTimeline animation)
        {
            builder.SetAnimationOut(animation);

            return(builder);
        }
Esempio n. 20
0
        static void SlideIn(FrameworkElement frameworkElement)
        {
            AnimationTimeline marginAnimation = CreateSlideInAnimation(frameworkElement);

            frameworkElement.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
            frameworkElement.Visibility = Visibility.Visible;
            DisableHiddenFrameworkElement(frameworkElement);
        }
Esempio n. 21
0
        private void remove(object sender, EventArgs e)
        {
            AnimationTimeline timeline  = (sender as AnimationClock).Timeline;
            TextBlock         uiElement = Storyboard.GetTarget(timeline) as TextBlock;

            stackpanel.Children.Remove(uiElement);
            stackpanel.UpdateLayout();
        }
Esempio n. 22
0
            /// <summary>
            /// Function for starting animation
            /// </summary>
            public void Animate()
            {
                AnimationTimeline animation = null;

                if (ThicknessProperty != null)
                {
                    var thickness = new Thickness();

                    thickness.Left   = Element.Margin.Left;
                    thickness.Top    = Element.Margin.Top;
                    thickness.Right  = Element.Margin.Right;
                    thickness.Bottom = Element.Margin.Bottom;

                    for (int i = 0; i < ThicknessProperty.Length; i++)
                    {
                        switch (ThicknessProperty[i])
                        {
                        case ThicknessAnimationProperty.Left:
                            thickness.Left = State ? EndValue[i] : StartValue[i];
                            break;

                        case ThicknessAnimationProperty.Top:
                            thickness.Top = State ? EndValue[i] : StartValue[i];
                            break;

                        case ThicknessAnimationProperty.Right:
                            thickness.Right = State ? EndValue[i] : StartValue[i];
                            break;

                        case ThicknessAnimationProperty.Bottom:
                            thickness.Bottom = State ? EndValue[i] : StartValue[i];
                            break;
                        }
                    }

                    animation = new ThicknessAnimation(thickness, Time);
                }
                else
                {
                    animation = new DoubleAnimation
                    {
                        From     = State ? StartValue[0] : EndValue[0],
                        To       = State ? EndValue[0] : StartValue[0],
                        Duration = Time
                    };
                }

                try
                {
                    Element.BeginAnimation(AnimateProperty, animation);
                }
                catch (Exception)
                {
                    System.Diagnostics.Debug.WriteLine($"{Key} Error");
                }

                State = !State;
            }
        /// <inheritdoc/>
        public override void AddToStoryboard(Storyboard storyBoard, AnimationTimeline timeline = null)
        {
            var animation = timeline ?? Get();

            Storyboard.SetTargetName(animation, RENDERTRANSFORM_OBJECT_NAME);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Direction == RenderTransformDirection.Horizontal ? "X" : "Y"));

            storyBoard.Children.Add(animation);
        }
Esempio n. 24
0
 private void CreateFadeOutAnimation()
 {
     fadeOutAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(3)))
     {
         DecelerationRatio = 0.7,
         FillBehavior      = FillBehavior.Stop
     };
     fadeOutAnimation.Completed += FadeAnimation_Completed;
 }
Esempio n. 25
0
        public static void DoAnimation(this FrameworkElement targetElement, AnimationTimeline animation, DependencyProperty targetProperty)
        {
            Storyboard storyboard = new Storyboard();

            Storyboard.SetTarget(animation, targetElement);
            Storyboard.SetTargetProperty(animation, new PropertyPath(targetProperty));
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
        public void RemoveAnimationTrack(AnimationTrack track)
        {
            USUndoManager.RegisterCompleteObjectUndo(AnimationTimeline, "Add New Track");
            AnimationTimeline.RemoveTrack(track);

            USUndoManager.RegisterCompleteObjectUndo(USHierarchy, "Add New Track");
            USHierarchy.RootItems.Remove(USHierarchy.RootItems.Where(item => ((USAnimationTimelineTrackHierarchyItem)item).AnimationTrack == track).First());

            USUndoManager.DestroyImmediate(track);
        }
Esempio n. 27
0
 public MainWindow()
 {
     InitializeComponent();
     TransparencyAnimation = new DoubleAnimation
     {
         From     = 0,
         To       = 1,
         Duration = TimeSpan.FromSeconds(0.5)
     };
 }
Esempio n. 28
0
        public static void BeginAnimation(IAnimatable Item, DependencyProperty dp, AnimationTimeline ATL, object FromValue, object ToValue, Action OnCompleted, SetExtentAnimationTimelineDelegate SetExtentValue)
        {
            if (ToValue == null)
            {
                return;
            }

            if (Item != null && Item is DependencyObject)
            {
                ATL.FillBehavior = FillBehavior.HoldEnd;

                if (SetExtentValue != null)
                {
                    SetExtentValue(ATL);
                }

                FillBehavior StatusValue = ATL.FillBehavior;
                ATL.FillBehavior = FillBehavior.Stop;

                DependencyObject ConvertItem = Item as DependencyObject;
                object           TargetValue = null;
                if (StatusValue == FillBehavior.Stop || ATL.AutoReverse)
                {
                    if (FromValue == null)
                    {
                        TargetValue = ConvertItem.GetValue(dp);
                    }
                    else
                    {
                        TargetValue = FromValue;
                    }
                }
                else
                {
                    TargetValue = ToValue;
                }

                ATL.Completed += new EventHandler(
                    delegate(object sender, EventArgs e)
                {
                    ConvertItem.SetValue(dp, TargetValue);
                    object CurValue = ConvertItem.GetValue(dp);
                    if (TargetValue != null && !TargetValue.Equals(CurValue))
                    {
                        return;
                    }

                    if (OnCompleted != null)
                    {
                        OnCompleted();
                    }
                });
                Item.BeginAnimation(dp, ATL, HandoffBehavior.SnapshotAndReplace);
            }
        }
Esempio n. 29
0
        public static void Add(DependencyObject element, AnimationKind type, AnimationTimeline animation)
        {
            switch (type)
            {
            case AnimationKind.BackgroundColor:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Background.Color"));
                break;

            case AnimationKind.BorderColor:
                Storyboard.SetTargetProperty(animation, new PropertyPath("(Border.BorderBrush).(SolidColorBrush.Color)"));
                break;

            case AnimationKind.BackgroundOpacity:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Background.Opacity"));
                break;

            case AnimationKind.DropShadowOpacity:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Effect.Opacity"));
                break;

            case AnimationKind.DropShadowBlur:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Effect.BlurRadius"));
                break;

            case AnimationKind.Opacity:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Opacity"));
                break;

            case AnimationKind.TranslateX:
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
                break;

            case AnimationKind.TranslateY:
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
                break;

            case AnimationKind.Margin:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Margin"));
                break;

            case AnimationKind.Width:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Width"));
                break;

            case AnimationKind.Height:
                Storyboard.SetTargetProperty(animation, new PropertyPath("Height"));
                break;

            default:
                break;
            }

            Storyboard.SetTarget(animation, element);
            sboard.Children.Add(animation);
        }
Esempio n. 30
0
        private void disappear(object sender, EventArgs e)
        {
            AnimationTimeline timeline  = (sender as AnimationClock).Timeline;
            TextBlock         uiElement = Storyboard.GetTarget(timeline) as TextBlock;
            //动画淡出
            DoubleAnimation daV = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromMilliseconds(animation_dis)));

            daV.Completed += new EventHandler(remove);
            Storyboard.SetTarget(daV, uiElement);
            uiElement.BeginAnimation(UIElement.OpacityProperty, daV);
        }
Esempio n. 31
0
 public void BeginAnimation(DependencyProperty property, AnimationTimeline animation)
 {
   BeginAnimation(property, animation, HandoffBehavior.SnapshotAndReplace);
 }
Esempio n. 32
0
 public void BeginAnimation(DependencyProperty property, AnimationTimeline animation, HandoffBehavior handoffBehavior) {}
 protected internal AnimationClock(AnimationTimeline timeline) : base(timeline) {}
 /// <summary>
 /// Creates a new empty AnimationClock to be used in a Clock
 /// tree.
 /// </summary>
 /// <param name="animation">The Animation used to define the new
 /// AnimationClock.</param>
 protected internal AnimationClock(AnimationTimeline animation)
     : base(animation)
 {
 }