Beispiel #1
0
        public Task AnimateText(AnimationDefinition animationDefinition, double interval)
        {
            var animations = new List <Task>();

            if ((LayoutRoot != null) &&
                (Text != null) &&
                (animationDefinition != null))
            {
                LayoutRoot.Children.Clear();
                var transparentBrush = new SolidColorBrush(Colors.Transparent);

                var delay = animationDefinition.Delay;

                for (int i = 0; i < Text.Length; i++)
                {
                    var s = Text.Substring(i, 1);
                    if (string.IsNullOrWhiteSpace(s))
                    {
                        continue;
                    }

                    var tb = new TextBlock
                    {
                        FontFamily = FontFamily,
                        FontSize   = FontSize,
                        FontStyle  = FontStyle,
                        FontWeight = FontWeight
                    };
                    if (i == 0)
                    {
                        tb.Text = Text.Substring(0, 1);
                    }
                    else
                    {
                        tb.Inlines.Add(new Run {
                            Text = Text.Substring(0, i), Foreground = transparentBrush
                        });
                        tb.Inlines.Add(new Run {
                            Text = Text.Substring(i, 1)
                        });
                    }
                    LayoutRoot.Children.Add(tb);

#if NETFX_CORE || WINDOWS_81_PORTABLE
                    if (DesignMode.DesignModeEnabled)
                    {
                        return(null);
                    }
#endif

                    animationDefinition.Delay = i * interval;
                    animations.Add(tb.AnimateAsync(animationDefinition));
                }

                animationDefinition.Delay = delay;
            }

            return(Task.WhenAll(animations));
        }
 internal void SetNextNavigationAnimation(
     AnimationDefinition closeAnimation,
     AnimationDefinition openAnimation,
     bool sequential)
 {
     OneOffAnimation_Close      = closeAnimation;
     OneOffkAnimation_Open      = openAnimation;
     OneOffAnimation_Sequential = sequential;
     _oneOff = true;
 }
        public static Storyboard AnimationStoryboard(
            FrameworkElement element,
            AnimationDefinition animationDefinition,
            Action completedAction = null)
        {
            var animations = animationDefinition.CreateAnimation(element);

            PrepareElement(element);

            var sb = new Storyboard();
            foreach (var animation in animations)
            {
                if (animationDefinition.PauseBefore > 0)
                    animation.BeginTime = TimeSpan.FromSeconds(animationDefinition.PauseBefore);

                Storyboard.SetTarget(animation, element);
                sb.Children.Add(animation);
            }

            if ((animationDefinition.PauseBefore > 0.0) ||
                (animationDefinition.PauseAfter > 0.0))
            {
                sb.Duration = new Duration(TimeSpan.FromSeconds(
                    animationDefinition.PauseBefore +
                    animationDefinition.Duration +
                    animationDefinition.PauseAfter));
            }

            sb.Completed += (sender, o) =>
            {
                Manager.RemoveStoryboard(element, sb);
                if (completedAction != null)
                    completedAction();
            };

            Manager.AddStoryboard(element, sb);

            if (animationDefinition.SpeedRatio > 0.0)
                sb.SpeedRatio = animationDefinition.SpeedRatio;
            if (animationDefinition.RepeatCount > 0)
                sb.RepeatBehavior = new RepeatBehavior(animationDefinition.RepeatCount);
            if (animationDefinition.RepeatDuration > 0)
                sb.RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(animationDefinition.RepeatDuration));
            if (animationDefinition.Forever)
                sb.RepeatBehavior = RepeatBehavior.Forever;
            sb.AutoReverse = animationDefinition.AutoReverse;

            if (animationDefinition.OpacityFromZero)
                element.Opacity = 0;

            if (animationDefinition.Delay > 0)
                sb.BeginTime = TimeSpan.FromSeconds(animationDefinition.Delay);

            return sb;
        }
        public static void SetOpen(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(OpenProperty, animationDefinition);

            if (animationDefinition.OpacityFromZero)
                element.Opacity = 0;

            element.Loaded += async (sender, args) =>
            {
                var idleDefinition = GetIdle(element);
                if (idleDefinition == null)
                {
                    await element.AnimateAsync(animationDefinition);
                }
            };
        }
Beispiel #5
0
        public static void SetOpen(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(OpenProperty, animationDefinition);

            if (animationDefinition.OpacityFromZero)
            {
                element.Opacity = 0;
            }

            element.Loaded += async(sender, args) =>
            {
                var idleDefinition = GetIdle(element);
                if (idleDefinition == null)
                {
                    await element.AnimateAsync(animationDefinition);
                }
            };
        }
        public static void SetClose(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(CloseProperty, animationDefinition);

            element.Loaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Add(element);
                }
            };
            element.Unloaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Remove(element);
                }
            };
        }
        public static void SetIdle(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(IdleProperty, animationDefinition);
            element.Loaded += async (sender, args) =>
            {
                var openAnimation = GetOpen(element);
                if (openAnimation != null)
                {
                    if (openAnimation.OpacityFromZero)
                        element.Opacity = 0;

                    await element.AnimateAsync(openAnimation);
                }

                animationDefinition.Forever = true;
                await element.AnimateAsync(animationDefinition);
            };

        }
Beispiel #8
0
        public static void SetClose(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(CloseProperty, animationDefinition);

            element.Loaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Add(element);
                }
            };
            element.Unloaded += (sender, args) =>
            {
                lock (_lockObject)
                {
                    CloseElements.Remove(element);
                }
            };
        }
        public static bool NavigateTo(
            this NavigationService navigationService,
            Uri source,
            AnimationDefinition closeAnimation,
            AnimationDefinition openAnimation,
            bool sequential)
        {
#if NETFX_CORE || WINDOWS_81_PORTABLE
            var frame = Window.Current.Content as AnimationFrame;
#elif WINDOWS_PHONE
            var frame = Application.Current.RootVisual as AnimationFrame;
#endif

            if (frame != null)
            {
                frame.SetNextNavigationAnimation(closeAnimation, openAnimation, sequential);
            }

            return(navigationService.Navigate(source));
        }
Beispiel #10
0
        public static void SetIdle(FrameworkElement element, AnimationDefinition animationDefinition)
        {
            element.SetValue(IdleProperty, animationDefinition);
            element.Loaded += async(sender, args) =>
            {
                var openAnimation = GetOpen(element);
                if (openAnimation != null)
                {
                    if (openAnimation.OpacityFromZero)
                    {
                        element.Opacity = 0;
                    }

                    await element.AnimateAsync(openAnimation);
                }

                animationDefinition.Forever = true;
                await element.AnimateAsync(animationDefinition);
            };
        }
        /***********************************************************************************/

        /// <summary>
        /// Animate a FrameworkElement using a preset animation sequence
        /// </summary>

        /*
         * public static Storyboard AnimationStoryboard(this FrameworkElement element, string animationName, Action completedAction = null)
         * {
         *  return AnimationManager.AnimationStoryboard(element, animationName, completedAction);
         * }
         */

        public static Task <FrameworkElement> AnimateAsync(
            this FrameworkElement element,
            AnimationDefinition animationDefinition
            )
        {
            var tcs = new TaskCompletionSource <FrameworkElement>();
            var sb  = AnimationManager.AnimationStoryboard(element, animationDefinition, () => tcs.SetResult(element));

            if (sb == null)
            {
                return(null);
            }
            Task t = AnimationManager.SplashScreenGone();

#if NETFX_CORE || WINDOWS_81_PORTABLE
            t.ContinueWith(x => element.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, sb.Begin));
#endif
#if WINDOWS_PHONE
            t.ContinueWith(x => element.Dispatcher.BeginInvoke(sb.Begin));
#endif
            return(tcs.Task);
        }
Beispiel #12
0
        public static Storyboard AnimationStoryboard(
            FrameworkElement element,
            AnimationDefinition animationDefinition,
            Action completedAction = null)
        {
            var animations = animationDefinition.CreateAnimation(element);

            PrepareElement(element);

            var sb = new Storyboard();

            foreach (var animation in animations)
            {
                if (animationDefinition.PauseBefore > 0)
                {
                    animation.BeginTime = TimeSpan.FromSeconds(animationDefinition.PauseBefore);
                }

                Storyboard.SetTarget(animation, element);
                sb.Children.Add(animation);
            }

            if ((animationDefinition.PauseBefore > 0.0) ||
                (animationDefinition.PauseAfter > 0.0))
            {
                sb.Duration = new Duration(TimeSpan.FromSeconds(
                                               animationDefinition.PauseBefore +
                                               animationDefinition.Duration +
                                               animationDefinition.PauseAfter));
            }

            sb.Completed += (sender, o) =>
            {
                Manager.RemoveStoryboard(element, sb);
                if (completedAction != null)
                {
                    completedAction();
                }
            };

            Manager.AddStoryboard(element, sb);

            if (animationDefinition.SpeedRatio > 0.0)
            {
                sb.SpeedRatio = animationDefinition.SpeedRatio;
            }
            if (animationDefinition.RepeatCount > 0)
            {
                sb.RepeatBehavior = new RepeatBehavior(animationDefinition.RepeatCount);
            }
            if (animationDefinition.RepeatDuration > 0)
            {
                sb.RepeatBehavior = new RepeatBehavior(TimeSpan.FromSeconds(animationDefinition.RepeatDuration));
            }
            if (animationDefinition.Forever)
            {
                sb.RepeatBehavior = RepeatBehavior.Forever;
            }
            sb.AutoReverse = animationDefinition.AutoReverse;

            if (animationDefinition.OpacityFromZero)
            {
                element.Opacity = 0;
            }

            if (animationDefinition.Delay > 0)
            {
                sb.BeginTime = TimeSpan.FromSeconds(animationDefinition.Delay);
            }

            return(sb);
        }
Beispiel #13
0
 public static void SetUnloadItem(ItemsControl element, AnimationDefinition value)
 {
     element.SetValue(UnloadItemProperty, value);
 }
Beispiel #14
0
 public static void SetLoadItem(ItemsControl element, AnimationDefinition value)
 {
     element.SetValue(LoadItemProperty, value);
     element.SizeChanged += OnSizeChanged;
 }
 internal void SetNextNavigationAnimation(
     AnimationDefinition closeAnimation, 
     AnimationDefinition openAnimation, 
     bool sequential)
 {
     OneOffAnimation_Close = closeAnimation;
     OneOffkAnimation_Open = openAnimation;
     OneOffAnimation_Sequential = sequential;
     _oneOff = true;
 }
Beispiel #16
0
 public static void SetUnloadItem(ItemsControl element, AnimationDefinition value)
 {
     element.SetValue(UnloadItemProperty, value);
 }
Beispiel #17
0
 public static void SetLoadItem(ItemsControl element, AnimationDefinition value)
 {
     element.SetValue(LoadItemProperty, value);
     element.SizeChanged += OnSizeChanged;
 }