Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animation - button and rich text box
#1
Video 
No XAML. Just the basics.
   
 
Code:
Copy      Help
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Documents;
            
var b = new wpfBuilder("Animation");

// Animate the Button's Width.
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 200;
myDoubleAnimation.To = 400;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
myDoubleAnimation.AutoReverse = true;
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

// Animate the RTB's height
DoubleAnimation myRtbAnimation = new DoubleAnimation();
myRtbAnimation.From = 35;
myRtbAnimation.To = 100;
myRtbAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
myRtbAnimation.AutoReverse = true;
myRtbAnimation.RepeatBehavior = RepeatBehavior.Forever;

// Create and animate a Brush to set the button's Background.
SolidColorBrush myBrush = new SolidColorBrush();
myBrush.Color = Colors.Blue;

// Create and animate a Brush to set the RTB's Background.
SolidColorBrush myRtbBrush = new SolidColorBrush();
myRtbBrush.Color = Colors.Blue;

// Button color animation
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = Colors.Blue;
myColorAnimation.To = Colors.Red;
myColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(7000));
myColorAnimation.AutoReverse = true;
myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;

// RTB background color animation
ColorAnimation myRtbColorAnimation = new ColorAnimation();
myRtbColorAnimation.From = Colors.Black;
myRtbColorAnimation.To = Colors.BlanchedAlmond;
myRtbColorAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(7000));
myRtbColorAnimation.AutoReverse = true;
myRtbColorAnimation.RepeatBehavior = RepeatBehavior.Forever;

// Apply the animation to the brushes' Color properties.
myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
myRtbBrush.BeginAnimation(SolidColorBrush.ColorProperty, myRtbColorAnimation);

// Start the grid to contain the RTB and the button
b.StartGrid().Margin(4, 4, 4, 4);
b.R.Add(out RichTextBox myRTB).Width(400).Font("Algerian", size: 24).Brush(myRtbBrush);

// Change text color in the RTB
TextRange tr = new TextRange(myRTB.Document.ContentStart, myRTB.Document.ContentEnd);
tr.Text = "RTB Content";
tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DarkGreen);

// Add the Button to the grid.
b.R.Add(out Button aButton, "Animated Button").Font("Comic Sans MS", size: 20).Brush(null, Brushes.AntiqueWhite);

// Animate the RTB
myRTB.BeginAnimation(RichTextBox.HeightProperty, myRtbAnimation);

// Apply the animation to the button's Width property.
aButton.BeginAnimation(Button.WidthProperty, myDoubleAnimation);
aButton.Background = myBrush;
aButton.Click += (o, e) => dialog.show("Animated button clicked", secondsTimeout: 2, title: "Animated button dialog");
b.End();
b.ShowDialog();


burque505


Forum Jump:


Users browsing this thread: 1 Guest(s)