Пример #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));
        }
Пример #2
0
        public void AnimateIn()
        {
            if (LayoutRoot == null)
            {
                return;
            }
            if (Text == null)
            {
                return;
            }

            LayoutRoot.Children.Clear();
            var transparentBrush = new SolidColorBrush(Colors.Transparent);

            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;
                }
#endif
                if (InAnimation != null)
                {
                    InAnimation.Delay = PauseBefore + (i * Interval);
                    tb.AnimateAsync(InAnimation);
                }

                if (IdleAnimation != null)
                {
                    IdleAnimation.PauseBefore = PauseBefore + (i * Interval);
                    IdleAnimation.PauseAfter  = ((Text.Length - i) * Interval) + PauseAfter;
                    IdleAnimation.Forever     = true;
                    tb.AnimateAsync(IdleAnimation);
                }
            }
        }