コード例 #1
0
        private void SlideUp()
        {
            Storyboard storyBoard = new Storyboard();

            MainCanvas.Children.Clear();
            MainCanvas.Background = ColorHelper.GetBrushFromString(_message.BackgroundColor);

            string text = _message.Text;

            string[] words = text.Split(' ');
            for (var i = 0; i <= words.Length - 1; i++)
            {
                Border b = new Border();
                b.BorderThickness = new Thickness(0);
                b.Width           = 800;
                b.Height          = 480;

                TextBlock tb = getTextBlock();
                tb.Text       = words[i];
                tb.FontSize   = getFontSize();
                tb.Foreground = ColorHelper.GetBrushFromString(_message.ForegroundColor);
                while (tb.ActualWidth > 800)
                {
                    tb.FontSize -= 1;
                    System.Diagnostics.Debug.WriteLine("FontSize: " + tb.FontSize);
                }
                tb.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                b.Child = tb;
                b.SetValue(Canvas.TopProperty, Convert.ToDouble(480));

                MainCanvas.Children.Add(b);

                double seconds = ((MAX_SPEED - _message.Speed) + 1) * SPEED_INTERVAL;

                double startingTime = (i * 2) * seconds;

                EasingDoubleKeyFrame edkf;

                // Hide elements during repeat

                DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();

                CircleEase ce = new CircleEase();
                ce.EasingMode = EasingMode.EaseOut;

                edkf                = new EasingDoubleKeyFrame();
                edkf.KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime));
                edkf.Value          = 480;
                edkf.EasingFunction = ce;
                animation.KeyFrames.Add(edkf);

                edkf                = new EasingDoubleKeyFrame();
                edkf.KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime + seconds));
                edkf.Value          = 0;
                edkf.EasingFunction = ce;
                animation.KeyFrames.Add(edkf);

                edkf                = new EasingDoubleKeyFrame();
                edkf.KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime + (seconds * 2)));
                edkf.Value          = 0;
                edkf.EasingFunction = ce;
                animation.KeyFrames.Add(edkf);

                edkf                = new EasingDoubleKeyFrame();
                edkf.KeyTime        = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime + (seconds * 3)));
                edkf.Value          = -480;
                edkf.EasingFunction = ce;
                animation.KeyFrames.Add(edkf);

                Storyboard.SetTarget(animation, b);
                Storyboard.SetTargetProperty(animation, new PropertyPath("(Canvas.Top)"));

                storyBoard.Children.Add(animation);
            }

            if (storyBoard.Children.Count > 0)
            {
                storyBoard.RepeatBehavior = RepeatBehavior.Forever;
                storyBoard.Begin();
            }
        }
コード例 #2
0
        private void Flash()
        {
            Storyboard storyBoard = new Storyboard();

            MainCanvas.Children.Clear();
            MainCanvas.Background = ColorHelper.GetBrushFromString(_message.BackgroundColor);

            Grid g = new Grid();

            g.Width  = 800;
            g.Height = 480;
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            MainCanvas.Children.Add(g);

            string text = _message.Text;

            string[] words = text.Split(' ');
            for (var i = 0; i <= words.Length - 1; i++)
            {
                TextBlock tb = getTextBlock();
                tb.Text       = words[i];
                tb.FontSize   = getFontSize();
                tb.Foreground = ColorHelper.GetBrushFromString(_message.ForegroundColor);
                while (tb.ActualWidth > 800)
                {
                    tb.FontSize -= 1;
                    System.Diagnostics.Debug.WriteLine("FontSize: " + tb.FontSize);
                }
                tb.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                tb.Visibility          = System.Windows.Visibility.Collapsed;

                g.Children.Add(tb);

                double seconds = ((MAX_SPEED - _message.Speed) + 1) * SPEED_INTERVAL;

                double startingTime = ((i * 2) + 1) * seconds;

                ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();

                DiscreteObjectKeyFrame visibleKeyFrame = new DiscreteObjectKeyFrame();
                visibleKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime));
                visibleKeyFrame.Value   = Visibility.Visible;
                animation.KeyFrames.Add(visibleKeyFrame);

                DiscreteObjectKeyFrame collapsedKeyFrame = new DiscreteObjectKeyFrame();
                collapsedKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime + seconds));
                collapsedKeyFrame.Value   = Visibility.Collapsed;
                animation.KeyFrames.Add(collapsedKeyFrame);

                Storyboard.SetTarget(animation, tb);
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Visibility)"));

                storyBoard.Children.Add(animation);
            }

            if (storyBoard.Children.Count > 0)
            {
                storyBoard.RepeatBehavior = RepeatBehavior.Forever;
                storyBoard.Begin();
            }
        }
コード例 #3
0
        void BackgroundListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string colorString = this.BackgroundListPicker.SelectedItem.ToString();

            MessageTextBox.Background = ColorHelper.GetBrushFromString(colorString);
        }