Esempio n. 1
0
        public void Execute(object parameter)
        {
            if (!(parameter is FrameworkElement element))
            {
                return;
            }

            var items = element.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup);

            items = items.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4);

            items = items.Where(l => (l as FrameworkElement)?.Tag?.ToString() != "Except" && !InvokeRandomSplitAnimationAction.GetIsExcept(l));

            var controls = items?.ToList();

            if (controls == null || controls.Count == 0)
            {
                return;
            }

            Storyboard storyboard = new Storyboard();

            controls.Reverse();

            for (int i = 0; i < controls.Count; i++)
            {
                TimeSpan span = TimeSpan.FromMilliseconds(i * SplitMilliSecond);

                ObjectAnimationUsingKeyFrames frames = new ObjectAnimationUsingKeyFrames();

                DiscreteObjectKeyFrame key1 = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(span));
                frames.KeyFrames.Add(key1);

                Storyboard.SetTarget(frames, controls[i]);
                Storyboard.SetTargetProperty(frames, new PropertyPath(FrameworkElement.VisibilityProperty));
                storyboard.Children.Add(frames);
            }

            storyboard.FillBehavior = FillBehavior.HoldEnd;
            storyboard.Begin();
        }
        /// <summary> 执行方法 </summary>
        protected override void Invoke(object parameter)
        {
            if (this.AssociatedObject == null)
            {
                return;
            }

            if (this.AutoFindParent)
            {
                this.Target = this.AssociatedObject.GetParent <Panel>();
            }

            if (this.Target == null)
            {
                this.Target = this.AssociatedObject;
            }

            IEnumerable <UIElement> children = null;

            if (IsUseAll)
            {
                children = this.Target.GetChildren <UIElement>().Where(l => l.RenderTransform is TransformGroup);

                children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4);

                children = children.Where(l => (l as FrameworkElement)?.Tag?.ToString() != "Except" && !InvokeRandomSplitAnimationAction.GetIsExcept(l));
            }
            else
            {
                if (this.Target is Panel panel)
                {
                    children = panel.Children?.Cast <UIElement>()?.Where(l => l.RenderTransform is TransformGroup);

                    children = children.Where(l => (l.RenderTransform as TransformGroup).Children.Count == 4 && !InvokeRandomSplitAnimationAction.GetIsExcept(l));
                }
            }

            if (children == null)
            {
                return;
            }

            var controls = children?.ToList();

            if (controls == null || controls.Count == 0)
            {
                return;
            }

            if (this.UseIndex)
            {
                controls = this.RandomList(controls);
            }

            Storyboard storyboard = new Storyboard();

            for (int i = 0; i < controls.Count; i++)
            {
                if (this.UseOrigin)
                {
                    controls[i].RenderTransformOrigin = this.GetRandomOrigin();
                }

                foreach (var item in Timelines.OfType <RandomDoubleAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    DoubleAnimation animation = item.ConvertTo();

                    if (item.BeginTime == TimeSpan.Zero)
                    {
                        DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();

                        EasingDoubleKeyFrame key1 = new EasingDoubleKeyFrame(animation.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                        frames.KeyFrames.Add(key1);
                        Storyboard.SetTarget(frames, controls[i]);
                        Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                        storyboard.Children.Add(frames);
                    }


                    animation.BeginTime = span + animation.BeginTime;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }

                foreach (var item in Timelines.OfType <ThicknessAnimation>())
                {
                    TimeSpan span = TimeSpan.FromMilliseconds(i * (SplitMilliSecond + item.Duration.TimeSpan.TotalMilliseconds));

                    TimeSpan end = item.Duration.TimeSpan + span;

                    ThicknessAnimationUsingKeyFrames frames = new ThicknessAnimationUsingKeyFrames();

                    EasingThicknessKeyFrame key1 = new EasingThicknessKeyFrame(item.From.Value, KeyTime.FromTimeSpan(TimeSpan.Zero));

                    frames.KeyFrames.Add(key1);
                    Storyboard.SetTarget(frames, controls[i]);
                    Storyboard.SetTargetProperty(frames, Storyboard.GetTargetProperty(item));
                    storyboard.Children.Add(frames);

                    ThicknessAnimation animation = item.Clone();
                    animation.BeginTime = span;
                    Storyboard.SetTarget(animation, controls[i]);

                    storyboard.Children.Add(animation);
                }
            }

            storyboard.FillBehavior = FillBehavior.HoldEnd;

            storyboard.RepeatBehavior = this.RepeatBehavior;

            storyboard.Begin();
        }