Exemplo n.º 1
0
        public static void StartClipAnimation(this Visual visual, ClipAnimationDirection direction, float to,
                                              double duration = 800, int delay = 0, CompositionEasingFunction easing = null, Action completed = null,
                                              AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count)
        {
            CompositionScopedBatch batch = null;

            if (visual.Size.X.Equals(0) || visual.Size.Y.Equals(0))
            {
                throw new ArgumentException("The visual is not properly sized.");
            }

            var compositor = visual.Compositor;

            if (visual.Clip == null)
            {
                var clip = compositor.CreateInsetClip();
                visual.Clip = clip;
            }

            if (completed != null)
            {
                batch            = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                batch.Completed += (s, e) => completed();
            }

            visual.Clip.StartAnimation($"{direction}Inset",
                                       compositor.CreateScalarKeyFrameAnimation(null, to, duration, delay, easing, iterationBehavior));

            batch?.End();
        }
Exemplo n.º 2
0
        public static void StartClipAnimation(this FrameworkElement element, ClipAnimationDirection direction, float to,
                                              double duration = 800, int delay = 0, CompositionEasingFunction easing = null, Action completed = null,
                                              AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count)
        {
            CompositionScopedBatch batch = null;

            var visual = element.Visual();

            // After we get the Visual of the View, we need to SIZE it 'cause by design the
            // Size is (0,0). Without doing this, clipping will not work.
            visual.Size = element.RenderSize.ToVector2();
            var compositor = visual.Compositor;

            if (visual.Clip == null)
            {
                var clip = compositor.CreateInsetClip();
                visual.Clip = clip;
            }

            if (completed != null)
            {
                batch            = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                batch.Completed += (s, e) => completed();
            }

            visual.Clip.StartAnimation($"{direction}Inset",
                                       compositor.CreateScalarKeyFrameAnimation(null, to, duration, delay, easing, iterationBehavior));

            batch?.End();
        }
Exemplo n.º 3
0
        public async static Task StartClipAnimation(this FrameworkElement element, ClipAnimationDirection direction, float to,
            double duration = 800, int delay = 0, CompositionEasingFunction easing = null, Action completed = null)
        {
            CompositionScopedBatch batch = null;

            var visual = element.Visual();
            // After we get the Visual of the View, we need to SIZE it 'cause by design the
            // Size is (0,0). Without doing this, clipping will not work.
            visual.Size = new Vector2(element.ActualWidth.ToFloat(), element.ActualHeight.ToFloat());
            var compositor = visual.Compositor;

            if (visual.Clip == null)
            {
                var clip = compositor.CreateInsetClip();
                visual.Clip = clip;
            }

            if (completed != null)
            {
                batch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                batch.Completed += (s, e) => completed();
            }

            if (delay > 0)
            {
                await Task.Delay(delay);
            }

            visual.Clip.StartAnimation($"{direction.ToString()}Inset", compositor.CreateScalarKeyFrameAnimation(to, duration, easing));

            if (batch != null)
            {
                batch.End();
            }
        }
        public static Task StartClipAnimationAsync(this FrameworkElement element, ClipAnimationDirection direction, float to,
                                                   double duration = 800, int delay = 0, CompositionEasingFunction easing = null,
                                                   AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count)
        {
            CompositionScopedBatch batch;

            var visual = element.Visual();

            // After we get the Visual of the View, we need to SIZE it 'cause by design the
            // Size is (0,0). Without doing this, clipping will not work.
            visual.Size = element.RenderSize.ToVector2();
            var compositor = visual.Compositor;

            if (visual.Clip == null)
            {
                var clip = compositor.CreateInsetClip();
                visual.Clip = clip;
            }

            var taskSource = new TaskCompletionSource <bool>();

            void Completed(object o, CompositionBatchCompletedEventArgs e)
            {
                batch.Completed -= Completed;
                taskSource.SetResult(true);
            }

            batch            = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            batch.Completed += Completed;

            visual.Clip.StartAnimation($"{direction}Inset",
                                       compositor.CreateScalarKeyFrameAnimation(null, to, duration, delay, easing, iterationBehavior));

            batch.End();

            return(taskSource.Task);
        }
        public static Task StartClipAnimationAsync(this Visual visual, ClipAnimationDirection direction, float to,
                                                   double duration = 800, int delay = 0, CompositionEasingFunction easing = null,
                                                   AnimationIterationBehavior iterationBehavior = AnimationIterationBehavior.Count)
        {
            CompositionScopedBatch batch;

            if (visual.Size.X.Equals(0) || visual.Size.Y.Equals(0))
            {
                throw new ArgumentException("The visual is not properly sized.");
            }

            var compositor = visual.Compositor;

            if (visual.Clip == null)
            {
                var clip = compositor.CreateInsetClip();
                visual.Clip = clip;
            }

            var taskSource = new TaskCompletionSource <bool>();

            void Completed(object o, CompositionBatchCompletedEventArgs e)
            {
                batch.Completed -= Completed;
                taskSource.SetResult(true);
            }

            batch            = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
            batch.Completed += Completed;

            visual.Clip.StartAnimation($"{direction}Inset",
                                       compositor.CreateScalarKeyFrameAnimation(null, to, duration, delay, easing, iterationBehavior));

            batch.End();

            return(taskSource.Task);
        }