TextBlock myTextBlock = new TextBlock(); myTextBlock.Text = "Hello, world!"; // Create the animation DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.From = 1; opacityAnimation.To = 0; opacityAnimation.Duration = TimeSpan.FromSeconds(2); // Begin the animation on the TextBlock control myTextBlock.BeginAnimation(TextBlock.OpacityProperty, opacityAnimation);
TextBlock myTextBlock = new TextBlock(); myTextBlock.Text = "Hello, world!"; // Create the animation ColorAnimation colorAnimation = new ColorAnimation(); colorAnimation.From = Colors.Red; colorAnimation.To = Colors.Blue; colorAnimation.Duration = TimeSpan.FromSeconds(3); // Begin the animation on the TextBlock control myTextBlock.BeginAnimation(TextBlock.ForegroundProperty, colorAnimation);Overall, the BeginAnimation method allows for smooth and dynamic animations of TextBlock controls within the WPF package library.