Ejemplo n.º 1
0
        ///--Method
        private Storyboard SetSb()
        {
            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(this.TargetText.Length / this.TypeSpeed * 1000));
            DiscreteStringKeyFrame        discreteStringKeyFrame;
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();

            stringAnimationUsingKeyFrames.Duration = new Duration(timeSpan);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));

            string tmp = string.Empty;

            foreach (char c in this.TargetText)
            {
                discreteStringKeyFrame         = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.Paced;
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }

            Storyboard sb = Application.Current.Resources["Sb_TypeWriter"] as Storyboard;

            sb.Children.Add(stringAnimationUsingKeyFrames);

            return(sb);
        }
Ejemplo n.º 2
0
        private StringAnimationUsingKeyFrames MakeTypewriteTextblock(string textToAnimate, string typeTextBlockName)
        {
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();

            stringAnimationUsingKeyFrames.FillBehavior = FillBehavior.HoldEnd;

            DiscreteStringKeyFrame discreteStringKeyFrame;
            string tmp = string.Empty;

            for (int i = 0; i <= textToAnimate.Length; i++)
            {
                discreteStringKeyFrame         = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300 * i)); //KeyTime.Paced;
                discreteStringKeyFrame.Value   = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);

                if (i == textToAnimate.Length)
                {
                    break;
                }
                tmp += textToAnimate[i];
            }

            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, typeTextBlockName);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));

            return(stringAnimationUsingKeyFrames);
        }
Ejemplo n.º 3
0
        public static void TypeWriter(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
        {
            Storyboard story = new Storyboard();

            story.FillBehavior = FillBehavior.HoldEnd;

            StringAnimationUsingKeyFrames saukf = new StringAnimationUsingKeyFrames();

            saukf.Duration = new Duration(timeSpan);

            string tmp = string.Empty;

            foreach (char c in textToAnimate)
            {
                DiscreteStringKeyFrame dskf = new DiscreteStringKeyFrame();
                dskf.KeyTime = KeyTime.Paced;
                tmp         += c;
                dskf.Value   = tmp;
                saukf.KeyFrames.Add(dskf);
            }
            Storyboard.SetTargetName(saukf, txt.Name);
            Storyboard.SetTargetProperty(saukf, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(saukf);

            story.Begin(txt);
        }
        public MainWindow()
        {
            InitializeComponent();

            /*
             * playPauseButton.IsEnabled = false;
             * nextButton.IsEnabled = false;
             * prevButton.IsEnabled = false;
             * shuffleButton.IsEnabled = false;
             * repeatButton.IsEnabled = false;
             */

            StringAnimationUsingKeyFrames strani = new StringAnimationUsingKeyFrames();

            strani.RepeatBehavior = RepeatBehavior.Forever;
            strani.Duration       = new Duration(new TimeSpan(0, 0, 12));
            strani.FillBehavior   = FillBehavior.HoldEnd;
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("W", TimeSpan.FromSeconds(1)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Wa", TimeSpan.FromSeconds(2)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Wai", TimeSpan.FromSeconds(3)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Wait", TimeSpan.FromSeconds(4)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waiti", TimeSpan.FromSeconds(5)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waitin", TimeSpan.FromSeconds(7)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waiting", TimeSpan.FromSeconds(9)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waiting.", TimeSpan.FromSeconds(10)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waiting..", TimeSpan.FromSeconds(11)));
            strani.KeyFrames.Add(new DiscreteStringKeyFrame("Waiting...", TimeSpan.FromSeconds(12)));

            Storyboard.SetTargetName(strani, loadingLabel.Name);
            Storyboard.SetTargetProperty(strani, new PropertyPath(Label.ContentProperty));
            story.Children.Add(strani);

            story.Begin(this);
        }
        private void RunAnimation(int value)
        {
            var  timeline = new StringAnimationUsingKeyFrames();
            long tick     = 200000;

            if (value > _displayNumber)
            {
                double jump = Math.Abs(value - _displayNumber) / 100d;
                for (double i = _displayNumber; i < value; i += jump)
                {
                    string stringvalue = ((int)i).ToString();
                    timeline.KeyFrames.Add(new DiscreteStringKeyFrame(stringvalue, KeyTime.FromTimeSpan(new TimeSpan(tick))));
                    tick += 200000;
                }
            }
            else
            {
                double jump = Math.Abs(value - _displayNumber) / 100d;
                for (double i = _displayNumber; i > value; i -= jump)
                {
                    string stringvalue = ((int)i).ToString();
                    timeline.KeyFrames.Add(new DiscreteStringKeyFrame(stringvalue, KeyTime.FromTimeSpan(new TimeSpan(tick))));
                    tick += 200000;
                }
            }
            timeline.KeyFrames.Add(new DiscreteStringKeyFrame(value.ToString(), KeyTime.FromTimeSpan(new TimeSpan(tick))));
            timeline.DecelerationRatio = 1;
            timeline.FillBehavior      = FillBehavior.HoldEnd;
            txtNumber.BeginAnimation(TextBlock.TextProperty, timeline);
        }
Ejemplo n.º 6
0
        private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
        {
            Storyboard storyboard = new Storyboard()
            {
                FillBehavior = FillBehavior.HoldEnd
            };
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrame = new StringAnimationUsingKeyFrames()
            {
                Duration = new Duration(timeSpan)
            };
            string empty = string.Empty;
            string str   = textToAnimate;

            for (int i = 0; i < str.Length; i++)
            {
                char chr = str[i];
                DiscreteStringKeyFrame discreteStringKeyFrame = new DiscreteStringKeyFrame()
                {
                    KeyTime = KeyTime.Paced
                };
                empty = string.Concat(empty, chr.ToString());
                discreteStringKeyFrame.Value = empty;
                stringAnimationUsingKeyFrame.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTargetName(stringAnimationUsingKeyFrame, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrame, new PropertyPath(TextBlock.TextProperty));
            storyboard.Children.Add(stringAnimationUsingKeyFrame);
            storyboard.Begin(txt);
        }
Ejemplo n.º 7
0
        private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
        {
            var story = new Storyboard
            {
                FillBehavior = FillBehavior.HoldEnd
            };

            DiscreteStringKeyFrame discreteStringKeyFrame;
            var stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames
            {
                Duration = new Duration(timeSpan)
            };

            var tmp = string.Empty;

            foreach (var c in textToAnimate)
            {
                discreteStringKeyFrame = new DiscreteStringKeyFrame
                {
                    KeyTime = KeyTime.Paced
                };
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }

            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);
            story.Begin(txt);
        }
Ejemplo n.º 8
0
        private void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
        {
            Storyboard story = new Storyboard();

            story.FillBehavior = FillBehavior.HoldEnd;
            //story.RepeatBehavior = RepeatBehavior.Forever;

            DiscreteStringKeyFrame        discreteStringKeyFrame;
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();

            stringAnimationUsingKeyFrames.Duration = new Duration(timeSpan);

            string tmp = string.Empty;

            foreach (char c in textToAnimate)
            {
                discreteStringKeyFrame         = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.Paced;
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);

            story.Begin(txt);
            //story.Stop(txt);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 在指定的文字层绑定控件上进行打字动画
        /// </summary>
        /// <param name="orgString">原字符串</param>
        /// <param name="appendString">要追加的字符串</param>
        /// <param name="msglayBinding">文字层的控件</param>
        /// <param name="wordTimeSpan">字符之间的打字时间间隔</param>
        private void TypeWriter(string orgString, string appendString, TextBlock msglayBinding, int wordTimeSpan)
        {
            //this.HideMessageTria();
            Storyboard MsgLayerTypingStory = new Storyboard();
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();
            Duration aniDuration = new Duration(TimeSpan.FromMilliseconds(wordTimeSpan * appendString.Length));

            stringAnimationUsingKeyFrames.Duration = aniDuration;
            MsgLayerTypingStory.Duration           = aniDuration;
            string tmp = orgString;

            foreach (char c in appendString)
            {
                var discreteStringKeyFrame = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.Paced;
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTarget(stringAnimationUsingKeyFrames, msglayBinding);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            MsgLayerTypingStory.Children.Add(stringAnimationUsingKeyFrames);
            MsgLayerTypingStory.Completed += this.TypeWriterAnimationCompletedCallback;
            MsgLayerTypingStory.Begin();
            MsgStoryboard = MsgLayerTypingStory;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 在指定的文字层绑定控件上进行打字动画
        /// </summary>
        /// <param name="appendString">要追加的字符串</param>
        /// <param name="msglayBinding">文字层的控件</param>
        /// <param name="wordTimeSpan">字符之间的打字时间间隔</param>
        private void TypeWriter(string appendString, TextBlock msglayBinding, int wordTimeSpan)
        {
            MsgLayerTypingStory = new Storyboard();
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();
            Duration aniDuration = new Duration(TimeSpan.FromMilliseconds(wordTimeSpan * appendString.Length + 2000));

            stringAnimationUsingKeyFrames.Duration = aniDuration;
            MsgLayerTypingStory.Duration           = aniDuration;
            string tmp = String.Empty;
            int    ctr = 0;

            foreach (char c in appendString)
            {
                var discreteStringKeyFrame = new DiscreteStringKeyFrame
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ctr++ *wordTimeSpan))
                };
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTarget(stringAnimationUsingKeyFrames, msglayBinding);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            MsgLayerTypingStory.Children.Add(stringAnimationUsingKeyFrames);
            MsgLayerTypingStory.RepeatBehavior = RepeatBehavior.Forever;
            MsgLayerTypingStory.Begin();
        }
Ejemplo n.º 11
0
        /// <summary type="AnimationTimeline" dos="private">
        /// Метод для изменения контента Lable-а
        /// </summary>
        /// <param name="delta"> Задержка между действиями. </param>
        /// <param name="seconds"> Текущий счётчик секунд. </param>
        /// <param name="label"> Ссылка на объект, который будет анимироваться. </param>
        /// <param name="newValue"> Новое занчение для свойства контент. </param>
        /// <returns> Возвращает анимационное событие типа AnimationTimeLine, привязаное к переданому Label-у. </returns>
        private static AnimationTimeline ChangeLabelContent(int seconds, int delta, ALabel label, string newValue)
        {
            var anim = new StringAnimationUsingKeyFrames();

            anim.KeyFrames.Add(new DiscreteStringKeyFrame(newValue,
                                                          TimeSpan.FromMilliseconds(seconds + delta)));

            Storyboard.SetTarget(anim, label);
            Storyboard.SetTargetProperty(anim, new PropertyPath(Label.ContentProperty));
            return(anim);
        }
Ejemplo n.º 12
0
        private void FillStoryBoard2(char c, TextBlock t)
        {
            ColorAnimation colani = new ColorAnimation()
            {
                BeginTime = TimeSpan.FromMilliseconds(400 * 19), From = Colors.LightBlue, To = Colors.Transparent, Duration = TimeSpan.FromMilliseconds(300)
            };
            SolidColorBrush s = new SolidColorBrush(Colors.LightBlue);

            ColorAnimation colani2 = new ColorAnimation()
            {
                BeginTime = TimeSpan.FromMilliseconds(400 * 19), From = Colors.LightBlue, To = Colors.Transparent, Duration = TimeSpan.FromMilliseconds(300)
            };
            SolidColorBrush s2 = new SolidColorBrush(Colors.LightBlue);

            StringAnimationUsingKeyFrames stas = new StringAnimationUsingKeyFrames();

            DiscreteStringKeyFrame desc  = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(_time));
            DiscreteStringKeyFrame desc2 = new DiscreteStringKeyFrame(c + "", TimeSpan.FromMilliseconds(_time + 300));

            stas.KeyFrames.Add(desc);
            stas.KeyFrames.Add(desc2);

            t.Background = s;

            if (_settings.Action == 0)
            {
                ((TextBlock)LeftPanel.Children[RightPanel.Children.Count - 1]).Background = s2;
            }
            else
            {
                ((TextBlock)RightPanel.Children[LeftPanel.Children.Count - 1]).Background = s2;
            }

            Storyboard.SetTarget(stas, t);
            Storyboard.SetTargetProperty(stas, new PropertyPath("(Text)"));
            if (_settings.Action == 0)
            {
                Storyboard.SetTarget(colani2, (TextBlock)LeftPanel.Children[RightPanel.Children.Count - 1]);
                Storyboard.SetTargetProperty(colani2, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)"));
            }

            else
            {
                Storyboard.SetTarget(colani2, (TextBlock)RightPanel.Children[LeftPanel.Children.Count - 1]);
                Storyboard.SetTargetProperty(colani2, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)"));
            }
            Storyboard.SetTarget(colani, t);
            Storyboard.SetTargetProperty(colani, new PropertyPath("(TextBlock.Background).(SolidColorBrush.Color)"));

            _time += 400;
            St.Children.Add(stas);
            St.Children.Add(colani);
            St.Children.Add(colani2);
        }
Ejemplo n.º 13
0
        private void KrajLabel_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Storyboard story = new Storyboard();
            StringAnimationUsingKeyFrames frames = new StringAnimationUsingKeyFrames();

            frames.Duration = new Duration(new TimeSpan(0, 0, 5));
            frames.KeyFrames.Add(new DiscreteStringKeyFrame(KrajLabel.Content.ToString()[0].ToString(), TimeSpan.FromSeconds(1)));
            frames.KeyFrames.Add(new DiscreteStringKeyFrame(KrajLabel.Content.ToString()[1].ToString(), TimeSpan.FromSeconds(2)));
            frames.KeyFrames.Add(new DiscreteStringKeyFrame(KrajLabel.Content.ToString()[2].ToString(), TimeSpan.FromSeconds(3)));
            frames.KeyFrames.Add(new DiscreteStringKeyFrame(KrajLabel.Content.ToString()[3].ToString(), TimeSpan.FromSeconds(4)));
            Storyboard.SetTargetName(frames, KrajLabel.Name);
            Storyboard.SetTargetProperty(frames, new PropertyPath(ContentProperty));
            story.Children.Add(frames);
            story.Begin(this);
        }
Ejemplo n.º 14
0
        public RegistracijaOkno(Shramba shramba)
        {
            InitializeComponent();
            this.shramba = shramba;
            StringAnimationUsingKeyFrames anistring = new StringAnimationUsingKeyFrames();

            anistring.Duration     = new Duration(new TimeSpan(0, 0, 4));
            anistring.FillBehavior = FillBehavior.HoldEnd;
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", ", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", F", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", Fr", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", Fri", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", Frie", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", Frien", TimeSpan.FromSeconds(0.5)));
            anistring.KeyFrames.Add(new DiscreteStringKeyFrame(", Friend", TimeSpan.FromSeconds(0.5)));
        }
        private void MyButton_Loaded(object sender, RoutedEventArgs e)
        {
            StringAnimationUsingKeyFrames anime = new StringAnimationUsingKeyFrames()
            {
                AutoReverse    = true,
                Duration       = new Duration(TimeSpan.FromSeconds(2.5)),
                RepeatBehavior = RepeatBehavior.Forever
            };

            anime.KeyFrames.Add(new DiscreteStringKeyFrame("", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0))));
            anime.KeyFrames.Add(new DiscreteStringKeyFrame("O", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))));
            anime.KeyFrames.Add(new DiscreteStringKeyFrame("OK", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
            anime.KeyFrames.Add(new DiscreteStringKeyFrame("OK!", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1.5))));
            anime.KeyFrames.Add(new DiscreteStringKeyFrame("OK!!", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))));

            myButton2.BeginAnimation(Button.ContentProperty, anime);
        }
Ejemplo n.º 16
0
        private Storyboard CreateFadeNextStoryboard()
        {
            var storyboard = new Storyboard();

            var animaForeground = new DoubleAnimation()
            {
                To       = 0,
                Duration = Duration,
            };

            Storyboard.SetTarget(animaForeground, _textBlock);
            Storyboard.SetTargetProperty(animaForeground, new PropertyPath("Opacity"));

            var totalMs = Duration.TotalMilliseconds;

            if (Interval != null)
            {
                totalMs += ((TimeSpan)Interval).TotalMilliseconds;
            }

            var animaForegroundReverse = new DoubleAnimation()
            {
                To        = 1,
                Duration  = Duration,
                BeginTime = TimeSpan.FromMilliseconds(totalMs),
            };

            Storyboard.SetTarget(animaForegroundReverse, _textBlock);
            Storyboard.SetTargetProperty(animaForegroundReverse, new PropertyPath("Opacity"));

            var animaString = new StringAnimationUsingKeyFrames();

            animaString.KeyFrames.Add(new DiscreteStringKeyFrame()
            {
                Value   = Text,
                KeyTime = KeyTime.FromTimeSpan(Duration),
            });
            Storyboard.SetTarget(animaString, _textBlock);
            Storyboard.SetTargetProperty(animaString, new PropertyPath("Text"));

            storyboard.Children.Add(animaForeground);
            storyboard.Children.Add(animaForegroundReverse);
            storyboard.Children.Add(animaString);

            return(storyboard);
        }
Ejemplo n.º 17
0
        public void addStringAnimation(String control, String value, Object property, int duration)
        {
            StringAnimationUsingKeyFrames anim = new StringAnimationUsingKeyFrames();
            DiscreteStringKeyFrame        edkf = new DiscreteStringKeyFrame();

            edkf.Value   = value;
            edkf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration));
            anim.KeyFrames.Add(edkf);
            anim.BeginTime = TimeSpan.FromSeconds(beginTime);
            beginTime     += duration;
            if (duration > 0)
            {
                animTimer.Add(beginTime);
            }
            Storyboard.SetTargetName(anim, control);
            Storyboard.SetTargetProperty(anim, new PropertyPath(property));
            sb.Children.Add(anim);
        }
Ejemplo n.º 18
0
        private void StartCountdown(FrameworkElement target)
        {
            var countdownAnimation = new StringAnimationUsingKeyFrames();

            for (var i = 5; i > 0; i--)
            {
                var keyTime = TimeSpan.FromSeconds(5 - i);
                var frame   = new DiscreteStringKeyFrame(i.ToString(), KeyTime.FromTimeSpan(keyTime));
                countdownAnimation.KeyFrames.Add(frame);
            }
            countdownAnimation.KeyFrames.Add(new DiscreteStringKeyFrame(" ", KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6))));
            Storyboard.SetTargetName(countdownAnimation, target.Name);
            Storyboard.SetTargetProperty(countdownAnimation, new PropertyPath(TextBlock.TextProperty));

            countdownStoryboard = new Storyboard();
            countdownStoryboard.Children.Add(countdownAnimation);
            countdownStoryboard.Completed += CountdownTimer_Completed;
            countdownStoryboard.Begin(this);
        }
Ejemplo n.º 19
0
        private void FillStoryBoard(char c, TextBlock t, Boolean timer)
        {
            StringAnimationUsingKeyFrames stas = new StringAnimationUsingKeyFrames();

            DiscreteStringKeyFrame desc  = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(_time));
            DiscreteStringKeyFrame desc2 = new DiscreteStringKeyFrame(c + "", TimeSpan.FromMilliseconds(_time + 300));
            DiscreteStringKeyFrame desc3 = new DiscreteStringKeyFrame("", TimeSpan.FromMilliseconds(400 * 19));

            stas.KeyFrames.Add(desc);
            stas.KeyFrames.Add(desc2);
            stas.KeyFrames.Add(desc3);

            Storyboard.SetTarget(stas, t);
            Storyboard.SetTargetProperty(stas, new PropertyPath("(Text)"));
            if (timer)
            {
                _time += 400;
            }
            St.Children.Add(stas);
        }
Ejemplo n.º 20
0
        private void GenerateAnimation()
        {
            // Create a storyboard to apply the animation.
            Storyboard tutorialStoryboard = new Storyboard();

            tutorialStoryboard.BeginTime = TimeSpan.FromMilliseconds(600);
            tutorialStoryboard.Duration  = TimeSpan.FromMilliseconds(2500);

            DoubleAnimation objectAnimation = MakeOpacityAnimation("part_cursor_rect", 0, 1, 700);

            objectAnimation.RepeatBehavior = RepeatBehavior.Forever;
            tutorialStoryboard.Children.Add(objectAnimation);

            StringAnimationUsingKeyFrames typeAnimation = MakeTypewriteTextblock(Keyword, "part_typed_tbl");

            tutorialStoryboard.Children.Add(typeAnimation);

            DoubleAnimation guideTblAnimation = MakeOpacityAnimation("part_guide_tbl", 1, 0, 0);

            guideTblAnimation.BeginTime = TimeSpan.FromMilliseconds(700);
            tutorialStoryboard.Children.Add(guideTblAnimation);

            int delayMilliSec = 400;

            for (int i = 1; i <= ResultCount; i++)
            {
                DoubleAnimation objectAnimationForLvi = MakeOpacityAnimation("part_lvi_" + i, 0, 1, 200);
                objectAnimationForLvi.BeginTime = TimeSpan.FromMilliseconds(delayMilliSec + (100 * i));
                tutorialStoryboard.Children.Add(objectAnimationForLvi);
            }

            tutorialStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            tutorialStoryboard.AutoReverse    = true;
            CustomStoryboard = tutorialStoryboard;

            //// Start the storyboard after the rectangle loads.
            //rootGrid.Loaded += delegate (object sender, RoutedEventArgs e)
            //{
            //    translationStoryboard.Begin(this);
            //};
        }
Ejemplo n.º 21
0
        public void Typewriter(string text, TextBlock block, TimeSpan timespan)
        {
            story.FillBehavior = FillBehavior.HoldEnd;
            DiscreteStringKeyFrame        discreteStringKeyFrame;
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames();

            stringAnimationUsingKeyFrames.Duration = new Duration(timespan);
            string tmp = string.Empty;

            foreach (char c in text)
            {
                discreteStringKeyFrame         = new DiscreteStringKeyFrame();
                discreteStringKeyFrame.KeyTime = KeyTime.Paced;
                tmp += c;
                discreteStringKeyFrame.Value = tmp;
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, block.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);
        }
Ejemplo n.º 22
0
        private void GetAnimation(Individual IndFromAlgorithm, int bias, double AnimTime, double AnimStart, bool EndOfGeneration, Ellipse El, TextBlock Number)
        {
            ElasticEase IFunc = new ElasticEase()
            {
                EasingMode   = EasingMode.EaseInOut,
                Oscillations = 25,
                Springiness  = 10
            };
            CircleEase IFunc1 = new CircleEase()
            {
            };
            DoubleAnimation ElWAnimation = new DoubleAnimation()//формируем анимацию для появления эллипса
            {
                From           = 35,
                To             = 35,
                Duration       = TimeSpan.FromSeconds(AnimTime),
                BeginTime      = TimeSpan.FromSeconds(AnimStart * bias),
                EasingFunction = IFunc1
            };

            El.BeginAnimation(Ellipse.WidthProperty, ElWAnimation);
            if (EndOfGeneration)// если особь крайняя крепим за ней событие отбора
            {
                ElWAnimation.Completed += Killing;
            }
            El.BeginAnimation(Ellipse.HeightProperty, ElWAnimation);

            StringAnimationUsingKeyFrames NumAnimation = new StringAnimationUsingKeyFrames()//формируем анимацию для появления текста на эллипсе
            {
                Duration  = TimeSpan.FromSeconds(0),
                BeginTime = TimeSpan.FromSeconds(AnimStart * bias),
            };

            NumAnimation.KeyFrames.Add(new DiscreteStringKeyFrame()
            {
                Value   = IndFromAlgorithm.x.ToString("F2") + "\n" + IndFromAlgorithm.y.ToString("F2"),
                KeyTime = KeyTime.FromPercent(1)
            });
            Number.BeginAnimation(TextBlock.TextProperty, NumAnimation);
        }
        private void WorkingAnimation(TextBlock control)
        {
            if (_story != null)
            {
                _story.Stop(this);
            }

            _story = new Storyboard();
            _story.FillBehavior   = FillBehavior.HoldEnd;
            _story.RepeatBehavior = RepeatBehavior.Forever;

            StringAnimationUsingKeyFrames stringAnimation = new StringAnimationUsingKeyFrames();

            stringAnimation.Duration       = TimeSpan.FromSeconds(2);
            stringAnimation.FillBehavior   = FillBehavior.Stop;
            stringAnimation.RepeatBehavior = RepeatBehavior.Forever;
            Storyboard.SetTargetName(stringAnimation, control.Name);
            Storyboard.SetTargetProperty(stringAnimation, new PropertyPath(TextBlock.TextProperty));

            DiscreteStringKeyFrame kf1 = new DiscreteStringKeyFrame("Working", TimeSpan.FromSeconds(0));
            DiscreteStringKeyFrame kf2 = new DiscreteStringKeyFrame(".Working.", TimeSpan.FromSeconds(0.5));
            DiscreteStringKeyFrame kf3 = new DiscreteStringKeyFrame("..Working..", TimeSpan.FromSeconds(1));
            DiscreteStringKeyFrame kf4 = new DiscreteStringKeyFrame("...Working...", TimeSpan.FromSeconds(1.5));

            stringAnimation.KeyFrames.Add(kf1);
            stringAnimation.KeyFrames.Add(kf2);
            stringAnimation.KeyFrames.Add(kf3);
            stringAnimation.KeyFrames.Add(kf4);

            _story.Children.Add(stringAnimation);

            DoubleAnimation doubleAnimation = new DoubleAnimation(-2.5, 3.5, TimeSpan.FromSeconds(5.4));

            Storyboard.SetTargetName(doubleAnimation, control.Name + "_gs2");
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(GradientStop.OffsetProperty));
            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            _story.Children.Add(doubleAnimation);
            _story.Begin(this, true);
        }
Ejemplo n.º 24
0
        private Storyboard CreateFadeStoryboard()
        {
            var storyboard = new Storyboard();

            var animaForeground = UIElementUtils.CreateAnimation(null,
                                                                 0,
                                                                 AnimationBeginTime,
                                                                 AnimationDuration,
                                                                 AnimationEase);

            Storyboard.SetTarget(animaForeground, _textBlock);
            Storyboard.SetTargetProperty(animaForeground, new PropertyPath(TextBlock.OpacityProperty));

            var totalMs = AnimationDuration.TotalMilliseconds + AnimationInterval.TotalMilliseconds;

            var animaForegroundReverse = UIElementUtils.CreateAnimation(null,
                                                                        1,
                                                                        TimeSpan.FromMilliseconds(totalMs),
                                                                        AnimationDuration,
                                                                        AnimationEase);

            Storyboard.SetTarget(animaForegroundReverse, _textBlock);
            Storyboard.SetTargetProperty(animaForegroundReverse, new PropertyPath(TextBlock.OpacityProperty));

            var animaString = new StringAnimationUsingKeyFrames();

            animaString.KeyFrames.Add(new DiscreteStringKeyFrame()
            {
                Value   = Text,
                KeyTime = KeyTime.FromTimeSpan(AnimationDuration),
            });
            Storyboard.SetTarget(animaString, _textBlock);
            Storyboard.SetTargetProperty(animaString, new PropertyPath(TextBlock.TextProperty));

            storyboard.Children.Add(animaForeground);
            storyboard.Children.Add(animaForegroundReverse);
            storyboard.Children.Add(animaString);

            return(storyboard);
        }
Ejemplo n.º 25
0
        public BuildWindow()
        {
            InitializeComponent();

            // "Building..." text animation
            StringAnimationUsingKeyFrames animBuilding = new StringAnimationUsingKeyFrames()
            {
                Duration       = new Duration(new TimeSpan(0, 0, 4)),
                RepeatBehavior = RepeatBehavior.Forever
            };

            animBuilding.KeyFrames.Add(new DiscreteStringKeyFrame("Building", TimeSpan.FromSeconds(0)));
            animBuilding.KeyFrames.Add(new DiscreteStringKeyFrame("Building.", TimeSpan.FromSeconds(1)));
            animBuilding.KeyFrames.Add(new DiscreteStringKeyFrame("Building..", TimeSpan.FromSeconds(2)));
            animBuilding.KeyFrames.Add(new DiscreteStringKeyFrame("Building...", TimeSpan.FromSeconds(3)));

            Storyboard.SetTargetName(animBuilding, BuildingLabel.Name);
            Storyboard.SetTargetProperty(animBuilding, new PropertyPath(Label.ContentProperty));
            Story.Children.Add(animBuilding);

            Story.Begin(this); // Pass this to prevent running animation after window is closed
        }
Ejemplo n.º 26
0
        public static Storyboard CreateFade(TextBlock element, TimeSpan totalSpan, string newText)
        {
            var halfSpan = TimeSpan.FromTicks(totalSpan.Ticks / 2);

            var storyboard = new Storyboard();

            var opacityFrames = new DoubleAnimationUsingKeyFrames();

            Storyboard.SetTarget(opacityFrames, element);
            Storyboard.SetTargetProperty(opacityFrames, new PropertyPath(UIElement.OpacityProperty));
            opacityFrames.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, TimeSpan.Zero));
            opacityFrames.KeyFrames.Add(new EasingDoubleKeyFrame(0.0, halfSpan));
            opacityFrames.KeyFrames.Add(new EasingDoubleKeyFrame(1.0, totalSpan));
            storyboard.Children.Add(opacityFrames);

            var textFrames = new StringAnimationUsingKeyFrames();

            Storyboard.SetTarget(textFrames, element);
            Storyboard.SetTargetProperty(textFrames, new PropertyPath(TextBlock.TextProperty));
            textFrames.KeyFrames.Add(new DiscreteStringKeyFrame(newText, halfSpan));
            storyboard.Children.Add(textFrames);

            return(storyboard);
        }
Ejemplo n.º 27
0
        private void Typewriter(List <string> sAnim, TextBlock txt, TimeSpan span)
        {
            Storyboard story = new Storyboard
            {
                FillBehavior   = FillBehavior.HoldEnd,
                RepeatBehavior = RepeatBehavior.Forever
            };

            DiscreteStringKeyFrame        discreteStringKeyFrame;
            StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames
            {
                Duration = new Duration(span)
            };

            for (int i = 0; i < 15; i++)
            {
                discreteStringKeyFrame = new DiscreteStringKeyFrame
                {
                    KeyTime = KeyTime.Uniform,
                    Value   = string.Empty
                };
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            foreach (string s in sAnim)
            {
                string tmp = string.Empty;
                foreach (char c in s)
                {
                    discreteStringKeyFrame = new DiscreteStringKeyFrame
                    {
                        KeyTime = KeyTime.Uniform
                    };
                    tmp += c;
                    discreteStringKeyFrame.Value = tmp;
                    stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
                    stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
                }
                for (int i = 0; i < 10; i++)
                {
                    discreteStringKeyFrame = new DiscreteStringKeyFrame
                    {
                        KeyTime = KeyTime.Uniform,
                        Value   = tmp
                    };
                    stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
                }
                for (int i = 0; i < s.Length; i++)
                {
                    discreteStringKeyFrame = new DiscreteStringKeyFrame
                    {
                        KeyTime = KeyTime.Uniform
                    };
                    tmp = tmp.Remove(tmp.Length - 1, 1);
                    discreteStringKeyFrame.Value = tmp;
                    stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
                }
                discreteStringKeyFrame = new DiscreteStringKeyFrame
                {
                    KeyTime = KeyTime.Uniform,
                    Value   = string.Empty
                };
                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
            }
            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
            story.Children.Add(stringAnimationUsingKeyFrames);

            story.Begin(txt);
        }
Ejemplo n.º 28
0
        private void Add(string text, int code)
        {
            base.Dispatcher.Invoke(() =>
            {
                if (!string.IsNullOrEmpty(text))
                {
                    TextBlock textBlock = new TextBlock();
                    logPanel.Children.Add(textBlock);
                    logCount++;
                    textBlock.Name = "text" + logCount.ToString();


                    //if (!atAnimation)
                    {
                        atAnimation = true;
                        double EndY;
                        TextBlock prev = logPanel.Children[0] as TextBlock;
                        if (prev.ActualHeight != double.NaN)
                        {
                            if (prev.ActualHeight < 20)
                            {
                                EndY = -(logCount * prev.ActualHeight / 1.0f - GlobalOutLogScrollViewer.ActualHeight) - 20.0f;
                            }
                            else
                            {
                                EndY = -(logCount * prev.ActualHeight / 4.0f - GlobalOutLogScrollViewer.ActualHeight);
                            }
                        }
                        else
                        {
                            EndY = -logCount * 15;
                        }

                        DoubleAnimation AnimationY = new DoubleAnimation(saveY, EndY, TimeSpan.FromSeconds(1));
                        AnimationY.Completed      += AnimationY_Completed;
                        saveY = EndY;

                        TranslateTransform Transform = new TranslateTransform();
                        logPanel.RenderTransform     = Transform;

                        Transform.BeginAnimation(TranslateTransform.YProperty, AnimationY);
                    }

                    ColorAnimation animation = new ColorAnimation
                    {
                        Duration = new Duration(TimeSpan.FromSeconds(10))
                    };

                    /*
                     * switch (code)
                     * {
                     *  case 0:
                     *      animation.To = SystemColors.ControlTextColor;
                     *      textBlock.Foreground = SystemColors.ControlTextBrush;
                     *      break;
                     *  case 1:
                     *      animation.To = SystemColors.WindowFrameColor;
                     *      textBlock.Foreground = SystemColors.ScrollBarBrush;
                     *      break;
                     *  case 3:
                     *      animation.To = ((SolidColorBrush)App.Current.Resources["OWLOSDangerAlpha4"]).Color;
                     *      textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSDanger"]).Color);
                     *      break;
                     *  default:
                     *      animation.To = SystemColors.HotTrackColor;
                     *      textBlock.Foreground = SystemColors.MenuBarBrush;
                     *      break;
                     * }
                     */

                    switch (code)
                    {
                    case 0:
                        animation.To         = SystemColors.ControlTextColor;
                        textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSSecondary"]).Color);
                        break;

                    case 1:
                        animation.To         = ((SolidColorBrush)App.Current.Resources["OWLOSWarningAlpha4"]).Color;
                        textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSWarning"]).Color);
                        break;

                    case 3:
                        animation.To         = Colors.Red; //((SolidColorBrush)App.Current.Resources["OWLOSDangerAlpha4"]).Color;
                        textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSDanger"]).Color);
                        break;

                    default:
                        animation.To         = SystemColors.ControlTextColor;
                        textBlock.Foreground = new SolidColorBrush(((SolidColorBrush)App.Current.Resources["OWLOSSecondary"]).Color);
                        break;
                    }


                    textBlock.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, animation);


                    //https://stackoverflow.com/questions/3430659/is-there-a-wpf-typewriter-effect
                    Storyboard story = new Storyboard
                    {
                        FillBehavior = FillBehavior.HoldEnd
                    };

                    StringAnimationUsingKeyFrames stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames
                    {
                        Duration = new Duration(TimeSpan.FromSeconds(1))
                    };


                    string tempText = string.Empty;
                    text            = DateTime.Now + " " + text;
                    foreach (char c in text)
                    {
                        DiscreteStringKeyFrame discreteStringKeyFrame = new DiscreteStringKeyFrame
                        {
                            KeyTime = KeyTime.Paced
                        };
                        tempText += c;
                        stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
                        if (tempText.Length < text.Length)
                        {
                            discreteStringKeyFrame.Value = tempText + "█";
                        }
                        else
                        {
                            discreteStringKeyFrame.Value = tempText;
                        }
                    }
                    Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
                    story.Children.Add(stringAnimationUsingKeyFrames);

                    story.Begin(textBlock);
                }
                //GlobalOutLogScrollViewer.ScrollToBottom();
            });
        }
Ejemplo n.º 29
0
        public void ShowWaitAnimation()
        {
            try
            {
                LoadingAnimationBorder.Child    = null;
                LoadingAnimationGrid.Visibility = Visibility.Visible;
                var stackPanel = new StackPanel
                {
                    Orientation         = Orientation.Horizontal,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                };
                LoadingAnimationBorder.Child = stackPanel;
                //var circularFadingLine = new CircularFadingLine();

                var vw = new VisualWrapper
                {
                    Child  = CreateAnnimationOnWorkerThread(),
                    Width  = 17,
                    Height = 17,
                    Margin = new Thickness(0, 0, 5, 0)
                };

                stackPanel.Children.Add(vw);

                var textBlock = new TextBlock {
                    Width = 80
                };

                var stranim = new StringAnimationUsingKeyFrames
                {
                    AutoReverse    = false,
                    RepeatBehavior = RepeatBehavior.Forever,
                    Duration       = new Duration(new TimeSpan(0, 0, 0, 2))
                };

                var kf1 = new DiscreteStringKeyFrame
                {
                    Value   = "Загрузка",
                    KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0))
                };

                var kf2 = new DiscreteStringKeyFrame
                {
                    Value   = "Загрузка.",
                    KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, 500))
                };

                var kf3 = new DiscreteStringKeyFrame
                {
                    Value   = "Загрузка..",
                    KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1))
                };

                var kf4 = new DiscreteStringKeyFrame
                {
                    Value   = "Загрузка...",
                    KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 1, 500))
                };

                stranim.KeyFrames.Add(kf1);
                stranim.KeyFrames.Add(kf2);
                stranim.KeyFrames.Add(kf3);
                stranim.KeyFrames.Add(kf4);

                stackPanel.Children.Add(textBlock);

                textBlock.BeginAnimation(TextBlock.TextProperty, stranim);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }